forked from k5mwe/DtCyber
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.c
126 lines (113 loc) · 3.24 KB
/
log.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*--------------------------------------------------------------------------
**
** Copyright (c) 2003-2011, Tom Hunter
**
** Name: log.c
**
** Description:
** Perform logging of abnormal conditions.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License version 3 as
** published by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License version 3 for more details.
**
** You should have received a copy of the GNU General Public License
** version 3 along with this program in file "license-gpl-3.0.txt".
** If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
**
**--------------------------------------------------------------------------
*/
/*
** -------------
** Include Files
** -------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "const.h"
#include "types.h"
#include "proto.h"
/*
** -----------------
** Private Constants
** -----------------
*/
/*
** -----------------------
** Private Macro Functions
** -----------------------
*/
/*
** -----------------------------------------
** Private Typedef and Structure Definitions
** -----------------------------------------
*/
/*
** ---------------------------
** Private Function Prototypes
** ---------------------------
*/
/*
** ----------------
** Public Variables
** ----------------
*/
/*
** -----------------
** Private Variables
** -----------------
*/
static FILE *logF;
/*
**--------------------------------------------------------------------------
**
** Public Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Initialize logging.
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void logInit(void)
{
logF = fopen("log.txt", "wt");
if (logF == NULL)
{
fprintf(stderr, "can't open log file");
}
}
/*--------------------------------------------------------------------------
** Purpose: Write a message to the error log.
**
** Parameters: Name Description.
** file file name where error occured
** line line where error occured
** fmt format string
** ... variable length argument list
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void logError(char *file, int line, char *fmt, ...)
{
va_list param;
va_start(param, fmt);
fprintf(logF, "[%s:%d] ", file, line);
vfprintf(logF, fmt, param);
va_end(param);
fprintf(logF, "\n");
fflush(logF);
}
/*--------------------------- End Of File ------------------------------*/