Browse Source

* log.[ch] : rename functions, add loglevel limiting

master
Alex 'AdUser' Z 9 years ago
parent
commit
cf7cf34910
  1. 2
      src/filelist.c
  2. 15
      src/log.c
  3. 3
      src/log.h

2
src/filelist.c

@ -37,7 +37,7 @@ f2b_filelist_from_glob(const char *pattern) {
if ((file = calloc(1, sizeof(f2b_logfile_t))) == NULL)
continue;
if (f2b_logfile_open(file, globbuf.gl_pathv[i]) == false) {
log_msg(log_error, "can't open file: %s: %s", globbuf.gl_pathv[i], strerror(errno));
f2b_log_msg(log_error, "can't open file: %s: %s", globbuf.gl_pathv[i], strerror(errno));
FREE(file);
continue;
}

15
src/log.c

@ -7,6 +7,8 @@
#define LOGLINE_MAX 1024
static log_msgtype_t minlevel = log_info;
static const char *loglevels[] = {
"debug",
"info",
@ -15,11 +17,14 @@ static const char *loglevels[] = {
"fatal",
};
void log_msg(log_msgtype_t l, const char *fmt, ...) {
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);
@ -27,3 +32,11 @@ void log_msg(log_msgtype_t l, const char *fmt, ...) {
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; }
}

3
src/log.h

@ -9,6 +9,7 @@ typedef enum {
log_fatal = 4
} log_msgtype_t;
void log_msg (log_msgtype_t l, const char *fmt, ...);
void f2b_log_msg(log_msgtype_t l, const char *fmt, ...);
void f2b_log_set_level(const char *level);
#endif /* F2B_LOG_H_ */

Loading…
Cancel
Save