You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
973 B
42 lines
973 B
#include <stdarg.h> |
|
#include <stdio.h> |
|
#include <string.h> |
|
|
|
#include "common.h" |
|
#include "log.h" |
|
|
|
#define LOGLINE_MAX 1024 |
|
|
|
static log_msgtype_t minlevel = log_info; |
|
|
|
static const char *loglevels[] = { |
|
"debug", |
|
"info", |
|
"warn", |
|
"error", |
|
"fatal", |
|
}; |
|
|
|
void f2b_log_msg(log_msgtype_t l, const char *fmt, ...) { |
|
va_list args; |
|
char line[LOGLINE_MAX] = ""; |
|
char msg[LOGLINE_MAX] = ""; |
|
|
|
if (l < minlevel) |
|
return; |
|
|
|
va_start(args, fmt); |
|
snprintf(msg, sizeof(msg), fmt, args); |
|
va_end(args); |
|
printf(line, LOGLINE_MAX, "[%s] %s", loglevels[l], msg); |
|
|
|
return; |
|
} |
|
|
|
void f2b_log_set_level(const char *level) { |
|
if (strcmp(level, "debug") == 0) { minlevel = log_debug; return; } |
|
if (strcmp(level, "info") == 0) { minlevel = log_info; return; } |
|
if (strcmp(level, "warn") == 0) { minlevel = log_warn; return; } |
|
if (strcmp(level, "error") == 0) { minlevel = log_error; return; } |
|
if (strcmp(level, "fatal") == 0) { minlevel = log_fatal; return; } |
|
}
|
|
|