Replace confini with toml
This commit is contained in:
parent
25eab5d38e
commit
79b1f3b2cf
27 changed files with 3081 additions and 5926 deletions
src
29
src/logger.c
29
src/logger.c
|
@ -17,10 +17,11 @@ const char *COLOR_EMERG = COLOR_MAGENTA;
|
|||
void
|
||||
logger_log(int level, const char *filename, int line, const char *func, const char *msg, ...)
|
||||
{
|
||||
if(global_config.log_level < level)
|
||||
if(global_config->logging.level < level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
va_list args;
|
||||
const char *level_str;
|
||||
const char *color;
|
||||
|
||||
|
@ -62,24 +63,28 @@ logger_log(int level, const char *filename, int line, const char *func, const ch
|
|||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
strftime(timestamp_str, 32, "%Y-%m-%d %H:%M:%S", localtime(&rawtime));
|
||||
size_t timestamp_len = strlen(timestamp_str);
|
||||
|
||||
char *buffer = malloc(sizeof(char) * (128 + strlen(msg)));
|
||||
sprintf(buffer, "%s[%5s] %s:%d:%s " COLOR_NONE "%s", color, level_str, filename, line, func, msg);
|
||||
char *buffer = malloc(sizeof(char) * (128 + strlen(msg) + timestamp_len));
|
||||
sprintf(buffer, "%s %s[%5s] %s:%d:%s " COLOR_NONE "%s", timestamp_str, color, level_str, filename, line, func, msg);
|
||||
|
||||
//fprintf(stream, "%s %s:%d:%s " COLOR_NONE, timestamp_str, filename, line, func);
|
||||
|
||||
va_list args;
|
||||
// start arg va_list and find log_len
|
||||
va_start(args, msg);
|
||||
vsyslog(level, buffer, args);
|
||||
size_t log_len = vsnprintf(NULL, 0, buffer, args); // NOLINT(clang-analyzer-valist.Uninitialized): clang-tidy bug
|
||||
va_end(args);
|
||||
|
||||
char *buffer_timed = malloc(sizeof(char) * (strlen(timestamp_str) + strlen(buffer) + 2));
|
||||
sprintf(buffer_timed, "%s %s", timestamp_str, buffer);
|
||||
char *log_line = malloc(sizeof(char) * (log_len + 1));
|
||||
|
||||
// start arg va_list again and write log_line
|
||||
va_start(args, msg);
|
||||
vfprintf(global_config.log_file, buffer_timed, args);
|
||||
fflush(global_config.log_file);
|
||||
vsprintf(log_line, buffer, args); // NOLINT(clang-analyzer-valist.Uninitialized): clang-tidy bug
|
||||
va_end(args);
|
||||
|
||||
syslog(level, "%s", log_line + timestamp_len + 1);
|
||||
|
||||
fprintf(global_config->logging.file, "%s", log_line);
|
||||
fflush(global_config->logging.file);
|
||||
|
||||
free(buffer);
|
||||
free(buffer_timed);
|
||||
free(log_line);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue