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");
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)
Log informational message for specific time.
LogLevel log_level
Minimum log level.
informational output about normal procedures
Fawkes library namespace.
void unlock()
Unlock the mutex.
virtual void log_error(const char *component, const char *format,...)
Log error message.
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)
Log debug message for specific time.
warning, should be investigated but software still functions, an example is that something was reques...
FileLogger(const char *filename, LogLevel min_level=LL_DEBUG)
Constructor.
virtual void vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va)
Log debug message for specific time.
Message iterator for exceptions.
error, may be recoverable (software still running) or not (software has to terminate).
virtual void vlog_debug(const char *component, const char *format, va_list va)
Log debug message.
iterator end()
Get end iterator for messages.
virtual void vlog_info(const char *component, const char *format, va_list va)
Log informational message.
virtual ~FileLogger()
Destructor.
Base class for exceptions in Fawkes.
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)
Log warning message for specific time.
virtual void vlog_warn(const char *component, const char *format, va_list va)
Log warning message.
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)
Log error message for specific time.
iterator begin()
Get iterator for messages.
debug output, relevant only when tracking down problems
virtual void log_warn(const char *component, const char *format,...)
Log warning message.
virtual void vlog_error(const char *component, const char *format, va_list va)
Log error message.
virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va)
Log informational message for specific time.
virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va)
Log warning message for specific time.
virtual void vtlog_error(struct timeval *t, const char *component, const char *format, va_list va)
Log error message for specific time.
void lock()
Lock this mutex.
Mutex mutual exclusion lock.
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
virtual void log_info(const char *component, const char *format,...)
Log informational message.