line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#define IMAGER_NO_CONTEXT |
2
|
|
|
|
|
|
|
#include "imageri.h" |
3
|
|
|
|
|
|
|
#include "imconfig.h" |
4
|
|
|
|
|
|
|
#include "log.h" |
5
|
|
|
|
|
|
|
#include |
6
|
|
|
|
|
|
|
#include |
7
|
|
|
|
|
|
|
#include "imerror.h" |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#ifdef IMAGER_LOG |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#define DTBUFF 50 |
12
|
|
|
|
|
|
|
#define DATABUFF DTBUFF+3+10+1+5+1+1 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#define LOG_DATE_FORMAT "%Y/%m/%d %H:%M:%S" |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
static i_mutex_t log_mutex; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
static void |
19
|
|
|
|
|
|
|
im_vloog(pIMCTX, int level, const char *fmt, va_list ap); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
/* |
22
|
|
|
|
|
|
|
* Logging is active |
23
|
|
|
|
|
|
|
*/ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
int |
26
|
56
|
|
|
|
|
|
im_init_log(pIMCTX, const char* name,int level) { |
27
|
56
|
|
|
|
|
|
i_clear_error(); |
28
|
|
|
|
|
|
|
|
29
|
56
|
100
|
|
|
|
|
if (!log_mutex) { |
30
|
37
|
|
|
|
|
|
log_mutex = i_mutex_new(); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
56
|
100
|
|
|
|
|
if (aIMCTX->lg_file) { |
34
|
19
|
50
|
|
|
|
|
if (aIMCTX->own_log) |
35
|
19
|
|
|
|
|
|
fclose(aIMCTX->lg_file); |
36
|
19
|
|
|
|
|
|
aIMCTX->lg_file = NULL; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
56
|
|
|
|
|
|
aIMCTX->log_level = level; |
40
|
56
|
100
|
|
|
|
|
if (level < 0) { |
41
|
19
|
|
|
|
|
|
aIMCTX->lg_file = NULL; |
42
|
|
|
|
|
|
|
} else { |
43
|
37
|
50
|
|
|
|
|
if (name == NULL) { |
44
|
0
|
|
|
|
|
|
aIMCTX->lg_file = stderr; |
45
|
0
|
|
|
|
|
|
aIMCTX->own_log = 0; |
46
|
|
|
|
|
|
|
} else { |
47
|
37
|
50
|
|
|
|
|
if (NULL == (aIMCTX->lg_file = fopen(name, "w+")) ) { |
48
|
0
|
|
|
|
|
|
im_push_errorf(aIMCTX, errno, "Cannot open file '%s': (%d)", name, errno); |
49
|
0
|
|
|
|
|
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
37
|
|
|
|
|
|
aIMCTX->own_log = 1; |
52
|
37
|
|
|
|
|
|
setvbuf(aIMCTX->lg_file, NULL, _IONBF, BUFSIZ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
56
|
100
|
|
|
|
|
if (aIMCTX->lg_file) { |
56
|
37
|
|
|
|
|
|
im_log((aIMCTX, 0,"Imager - log started (level = %d)\n", level)); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
56
|
|
|
|
|
|
return aIMCTX->lg_file != NULL; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
void |
63
|
0
|
|
|
|
|
|
i_fatal(int exitcode,const char *fmt, ... ) { |
64
|
|
|
|
|
|
|
va_list ap; |
65
|
0
|
|
|
|
|
|
dIMCTX; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if (aIMCTX->lg_file != NULL) { |
68
|
0
|
|
|
|
|
|
va_start(ap,fmt); |
69
|
0
|
|
|
|
|
|
im_vloog(aIMCTX, 0, fmt, ap); |
70
|
0
|
|
|
|
|
|
va_end(ap); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
exit(exitcode); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
void |
76
|
0
|
|
|
|
|
|
im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) { |
77
|
|
|
|
|
|
|
va_list ap; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if (aIMCTX->lg_file != NULL) { |
80
|
0
|
|
|
|
|
|
va_start(ap,fmt); |
81
|
0
|
|
|
|
|
|
im_vloog(aIMCTX, 0, fmt, ap); |
82
|
0
|
|
|
|
|
|
va_end(ap); |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
exit(exitcode); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
/* |
88
|
|
|
|
|
|
|
=item i_loog(level, format, ...) |
89
|
|
|
|
|
|
|
=category Logging |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This is an internal function called by the mm_log() macro. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
*/ |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
static void |
97
|
61925
|
|
|
|
|
|
im_vloog(pIMCTX, int level, const char *fmt, va_list ap) { |
98
|
|
|
|
|
|
|
time_t timi; |
99
|
|
|
|
|
|
|
struct tm *str_tm; |
100
|
|
|
|
|
|
|
char date_buffer[DTBUFF]; |
101
|
|
|
|
|
|
|
|
102
|
61925
|
50
|
|
|
|
|
if (!aIMCTX || !aIMCTX->lg_file || level > aIMCTX->log_level) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return; |
104
|
|
|
|
|
|
|
|
105
|
61925
|
|
|
|
|
|
i_mutex_lock(log_mutex); |
106
|
|
|
|
|
|
|
|
107
|
61925
|
|
|
|
|
|
timi = time(NULL); |
108
|
61925
|
|
|
|
|
|
str_tm = localtime(&timi); |
109
|
61925
|
|
|
|
|
|
strftime(date_buffer, DTBUFF, LOG_DATE_FORMAT, str_tm); |
110
|
61925
|
|
|
|
|
|
fprintf(aIMCTX->lg_file, "[%s] %10s:%-5d %3d: ", date_buffer, |
111
|
|
|
|
|
|
|
aIMCTX->filename, aIMCTX->line, level); |
112
|
61925
|
|
|
|
|
|
vfprintf(aIMCTX->lg_file, fmt, ap); |
113
|
61925
|
|
|
|
|
|
fflush(aIMCTX->lg_file); |
114
|
|
|
|
|
|
|
|
115
|
61925
|
|
|
|
|
|
i_mutex_unlock(log_mutex); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
void |
119
|
61933
|
|
|
|
|
|
i_loog(int level,const char *fmt, ... ) { |
120
|
61933
|
|
|
|
|
|
dIMCTX; |
121
|
|
|
|
|
|
|
va_list ap; |
122
|
|
|
|
|
|
|
|
123
|
61933
|
100
|
|
|
|
|
if (!aIMCTX || !aIMCTX->lg_file || level > aIMCTX->log_level) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
124
|
19590
|
|
|
|
|
|
return; |
125
|
|
|
|
|
|
|
|
126
|
42343
|
|
|
|
|
|
va_start(ap,fmt); |
127
|
42343
|
|
|
|
|
|
im_vloog(aIMCTX, level, fmt, ap); |
128
|
42343
|
|
|
|
|
|
va_end(ap); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
void |
132
|
27056
|
|
|
|
|
|
im_loog(pIMCTX, int level,const char *fmt, ... ) { |
133
|
|
|
|
|
|
|
va_list ap; |
134
|
|
|
|
|
|
|
|
135
|
27056
|
50
|
|
|
|
|
if (!aIMCTX || !aIMCTX->lg_file || level > aIMCTX->log_level) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
136
|
7474
|
|
|
|
|
|
return; |
137
|
|
|
|
|
|
|
|
138
|
19582
|
|
|
|
|
|
va_start(ap,fmt); |
139
|
19582
|
|
|
|
|
|
im_vloog(aIMCTX, level, fmt, ap); |
140
|
19582
|
|
|
|
|
|
va_end(ap); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
/* |
144
|
|
|
|
|
|
|
=item i_lhead(file, line) |
145
|
|
|
|
|
|
|
=category Logging |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This is an internal function called by the mm_log() macro. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
*/ |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
void |
153
|
88989
|
|
|
|
|
|
im_lhead(pIMCTX, const char *file, int line) { |
154
|
88989
|
100
|
|
|
|
|
if (aIMCTX && aIMCTX->lg_file != NULL) { |
|
|
100
|
|
|
|
|
|
155
|
67894
|
|
|
|
|
|
aIMCTX->filename = file; |
156
|
67894
|
|
|
|
|
|
aIMCTX->line = line; |
157
|
|
|
|
|
|
|
} |
158
|
88989
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
61933
|
|
|
|
|
|
void i_lhead(const char *file, int line) { |
161
|
61933
|
|
|
|
|
|
dIMCTX; |
162
|
|
|
|
|
|
|
|
163
|
61933
|
|
|
|
|
|
im_lhead(aIMCTX, file, line); |
164
|
61933
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
#else |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
/* |
169
|
|
|
|
|
|
|
* Logging is inactive - insert dummy functions |
170
|
|
|
|
|
|
|
*/ |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
int im_init_log(pIMCTX, const char* name,int onoff) { |
173
|
|
|
|
|
|
|
i_clear_error(); |
174
|
|
|
|
|
|
|
i_push_error(0, "Logging disabled"); |
175
|
|
|
|
|
|
|
return 0; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
void i_fatal(int exitcode,const char *fmt, ... ) { exit(exitcode); } |
179
|
|
|
|
|
|
|
void im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) { exit(exitcode); } |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
void |
182
|
|
|
|
|
|
|
i_loog(int level,const char *fmt, ... ) { |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
void |
186
|
|
|
|
|
|
|
im_loog(pIMCTX, int level,const char *fmt, ... ) { |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
void |
190
|
|
|
|
|
|
|
i_lhead(const char *file, int line) { } |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
void |
193
|
|
|
|
|
|
|
im_lhead(pIMCTX, const char *file, int line) { } |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
#endif |