Initial commit. It's far from finished.

This commit is contained in:
2016-08-08 11:12:06 +03:00
commit e9f3673bfd
30 changed files with 1948 additions and 0 deletions

64
log_trace.c Normal file
View File

@@ -0,0 +1,64 @@
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include "log_trace.h"
#include "confparser.h"
void log_trace(LOG_LEVEL lvl, char *fmt, ... )
{
LOG_LEVEL cur_lvl = conf.rmps.loglevel - '0';
if (lvl <= cur_lvl) {
va_list list;
int fallback = 0;
FILE *fd;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
if (lvl == ERROR || lvl == WARNING) {
fd = fopen(conf.rmps.errlog, "a");
if (!fd) {
fprintf( stderr,
"Failed to append errlog: %s. Redirecting to stderr:\n",
conf.rmps.errlog );
fd = stderr;
fallback = 1;
}
fprintf( fd,
"[%d-%02d-%02d %02d:%02d:%02d] %s: ",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
lvl == ERROR ? "ERROR" : "WARNING" );
} else {
fd = fopen(conf.rmps.logfile, "a");
if (!fd) {
fprintf( stderr,
"Failed to append logfile: %s. Redirecting to stderr:\n",
conf.rmps.logfile );
fd = stderr;
fallback = 1;
}
fprintf( fd,
"[%d-%02d-%02d %02d:%02d:%02d] %s: ",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
lvl == INFO ? "INFO" : "VERBOSE" );
}
va_start(list, fmt);
vfprintf(fd, fmt, list);
fprintf(fd, "\n");
va_end(list);
if (!fallback)
fclose(fd);
} else
return;
fflush(stdout);
}