Browse Source

* log.[ch]

master
Alex 'AdUser' Z 9 years ago
parent
commit
e7da98c7b5
  1. 10
      src/log.c
  2. 1
      src/log.h

10
src/log.c

@ -7,6 +7,14 @@
#define LOGLINE_MAX 1024 #define LOGLINE_MAX 1024
static const char *loglevels[] = {
"debug",
"info",
"warn",
"error",
"fatal",
};
void log_msg(log_msgtype_t l, const char *fmt, ...) { void log_msg(log_msgtype_t l, const char *fmt, ...) {
va_list args; va_list args;
char line[LOGLINE_MAX] = ""; char line[LOGLINE_MAX] = "";
@ -15,7 +23,7 @@ void log_msg(log_msgtype_t l, const char *fmt, ...) {
va_start(args, fmt); va_start(args, fmt);
snprintf(msg, sizeof(msg), fmt, args); snprintf(msg, sizeof(msg), fmt, args);
va_end(args); va_end(args);
strncat(line, msg, sizeof(line)); printf(line, LOGLINE_MAX, "[%s] %s", loglevels[l], msg);
return; return;
} }

1
src/log.h

@ -4,7 +4,6 @@
typedef enum { typedef enum {
log_debug = 0, log_debug = 0,
log_info = 1, log_info = 1,
log_note = 1,
log_warn = 2, log_warn = 2,
log_error = 3, log_error = 3,
log_fatal = 4 log_fatal = 4

Loading…
Cancel
Save