25 #include <logging/file.h>
26 #include <utils/system/file.h>
28 #include <core/threading/mutex.h>
54 int fd = open(filename, O_RDWR | O_CREAT | O_APPEND,
55 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
57 throw Exception(errno,
"Failed to open log file %s", filename);
59 log_file = fdopen(fd,
"a");
61 now_s = (
struct tm *)malloc(
sizeof(
struct tm));
80 va_start(arg, format);
90 va_start(arg, format);
100 va_start(arg, format);
110 va_start(arg, format);
121 gettimeofday(&now, NULL);
123 localtime_r(&now.tv_sec, now_s);
125 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"D", now_s->tm_hour,
126 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
127 fprintf(log_file,
"%s", *i);
128 fprintf(log_file,
"\n");
141 gettimeofday(&now, NULL);
143 localtime_r(&now.tv_sec, now_s);
145 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"I", now_s->tm_hour,
146 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
147 fprintf(log_file,
"%s", *i);
148 fprintf(log_file,
"\n");
161 gettimeofday(&now, NULL);
163 localtime_r(&now.tv_sec, now_s);
165 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"W", now_s->tm_hour,
166 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
167 fprintf(log_file,
"%s", *i);
168 fprintf(log_file,
"\n");
181 gettimeofday(&now, NULL);
183 localtime_r(&now.tv_sec, now_s);
185 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"E", now_s->tm_hour,
186 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
187 fprintf(log_file,
"%s", *i);
188 fprintf(log_file,
"\n");
201 gettimeofday(&now, NULL);
203 localtime_r(&now.tv_sec, now_s);
204 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"D", now_s->tm_hour,
205 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
206 vfprintf(log_file, format, va);
207 fprintf(log_file,
"\n");
219 gettimeofday(&now, NULL);
221 localtime_r(&now.tv_sec, now_s);
222 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"I", now_s->tm_hour,
223 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
224 vfprintf(log_file, format, va);
225 fprintf(log_file,
"\n");
237 gettimeofday(&now, NULL);
239 localtime_r(&now.tv_sec, now_s);
240 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"W", now_s->tm_hour,
241 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
242 vfprintf(log_file, format, va);
243 fprintf(log_file,
"\n");
255 gettimeofday(&now, NULL);
257 localtime_r(&now.tv_sec, now_s);
258 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"E", now_s->tm_hour,
259 now_s->tm_min, now_s->tm_sec, (
long)now.tv_usec, component);
260 vfprintf(log_file, format, va);
261 fprintf(log_file,
"\n");
272 va_start(arg, format);
282 va_start(arg, format);
292 va_start(arg, format);
302 va_start(arg, format);
313 localtime_r(&t->tv_sec, now_s);
315 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"D", now_s->tm_hour,
316 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
317 fprintf(log_file,
"%s", *i);
318 fprintf(log_file,
"\n");
331 localtime_r(&t->tv_sec, now_s);
333 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"I", now_s->tm_hour,
334 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
335 fprintf(log_file,
"%s", *i);
336 fprintf(log_file,
"\n");
349 localtime_r(&t->tv_sec, now_s);
351 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"W", now_s->tm_hour,
352 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
353 fprintf(log_file,
"%s", *i);
354 fprintf(log_file,
"\n");
367 localtime_r(&t->tv_sec, now_s);
369 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s [EXCEPTION]: ",
"E", now_s->tm_hour,
370 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
371 fprintf(log_file,
"%s", *i);
372 fprintf(log_file,
"\n");
385 localtime_r(&t->tv_sec, now_s);
386 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"D", now_s->tm_hour,
387 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
388 vfprintf(log_file, format, va);
389 fprintf(log_file,
"\n");
401 localtime_r(&t->tv_sec, now_s);
402 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"I", now_s->tm_hour,
403 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
404 vfprintf(log_file, format, va);
405 fprintf(log_file,
"\n");
417 localtime_r(&t->tv_sec, now_s);
418 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"W", now_s->tm_hour,
419 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
420 vfprintf(log_file, format, va);
421 fprintf(log_file,
"\n");
433 localtime_r(&t->tv_sec, now_s);
434 fprintf(log_file,
"%s %02d:%02d:%02d.%06ld %s: ",
"E", now_s->tm_hour,
435 now_s->tm_min, now_s->tm_sec, (
long)t->tv_usec, component);
436 vfprintf(log_file, format, va);
437 fprintf(log_file,
"\n");