23b1d6660c
CI / lint (push) Failing after 16s
CI / build-and-test (push) Has been skipped
CI / sanitizers (address) (push) Has been skipped
CI / sanitizers (thread) (push) Has been skipped
CI / lint (pull_request) Failing after 44s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (thread) (pull_request) Has been skipped
- Reformat all C/H files to match .clang-format (LLVM style) - Fix 26 cppcheck const-correctness warnings (constParameterPointer, constVariablePointer, constVariable) - Update function declarations in headers to match const parameters
28 lines
751 B
C
28 lines
751 B
C
#include "log.h"
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
static const char* log_level_strings[] = {"DEBUG", "INFO", "WARN", "ERROR"};
|
|
static LogLevel current_log_level = LOG_LEVEL_WARNING;
|
|
|
|
void set_log_level(LogLevel level) {
|
|
current_log_level = level;
|
|
}
|
|
|
|
void log_message(LogLevel log_level, char* format, ...) {
|
|
if (log_level < current_log_level)
|
|
return;
|
|
time_t now = time(NULL);
|
|
const struct tm* t = localtime(&now);
|
|
|
|
fprintf(stderr, "%04d-%02d-%02d %02d:%02d:%02d [%s]: ", t->tm_year + 1900, t->tm_mon + 1,
|
|
t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, log_level_strings[log_level]);
|
|
|
|
va_list args;
|
|
va_start(args, format);
|
|
vfprintf(stderr, format, args);
|
|
va_end(args);
|
|
fprintf(stderr, "\n");
|
|
}
|