|
|
@ -39,16 +39,14 @@ void f2b_log_msg(log_msgtype_t l, const char *fmt, ...) { |
|
|
|
vsnprintf(msg, sizeof(msg), fmt, args); |
|
|
|
vsnprintf(msg, sizeof(msg), fmt, args); |
|
|
|
va_end(args); |
|
|
|
va_end(args); |
|
|
|
|
|
|
|
|
|
|
|
if (!logfile) |
|
|
|
|
|
|
|
logfile = stderr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (dest) { |
|
|
|
switch (dest) { |
|
|
|
case log_syslog: |
|
|
|
case log_syslog: |
|
|
|
syslog(get_facility(l), "%s", msg); |
|
|
|
syslog(get_facility(l), "%s", msg); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
case log_stderr: |
|
|
|
case log_stderr: |
|
|
|
|
|
|
|
logfile = stderr; |
|
|
|
case log_file: |
|
|
|
case log_file: |
|
|
|
default: |
|
|
|
|
|
|
|
fprintf(logfile, "[%s] %s\n", loglevels[l], msg); |
|
|
|
fprintf(logfile, "[%s] %s\n", loglevels[l], msg); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -64,28 +62,23 @@ void f2b_log_set_level(const char *level) { |
|
|
|
if (strcmp(level, "fatal") == 0) { minlevel = log_fatal; return; } |
|
|
|
if (strcmp(level, "fatal") == 0) { minlevel = log_fatal; return; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void f2b_log_set_dest(const char *target) { |
|
|
|
void f2b_log_setup(const char *target, const char *path) { |
|
|
|
if (strcmp(target, "syslog") == 0) { dest = log_syslog; return; } |
|
|
|
if (strcmp(target, "syslog") == 0) { |
|
|
|
if (strcmp(target, "stderr") == 0) { dest = log_stderr; return; } |
|
|
|
dest = log_syslog; |
|
|
|
if (strcmp(target, "file") == 0) { dest = log_file; return; } |
|
|
|
openlog("f2b", LOG_CONS, LOG_DAEMON); |
|
|
|
} |
|
|
|
return; |
|
|
|
|
|
|
|
} else |
|
|
|
void f2b_log_setup(const char *path) { |
|
|
|
if (strcmp(target, "file") == 0 && *path != '\0') { |
|
|
|
switch (dest) { |
|
|
|
dest = log_file; |
|
|
|
case log_file: |
|
|
|
if (logfile) |
|
|
|
if (logfile) |
|
|
|
fclose(logfile); |
|
|
|
fclose(logfile); |
|
|
|
if ((logfile = fopen(path, "a")) == NULL) |
|
|
|
if ((logfile = fopen(path, "a")) == NULL) |
|
|
|
dest = log_stderr, logfile = stderr; |
|
|
|
dest = log_stderr, logfile = stderr; |
|
|
|
f2b_log_msg(log_error, "can't open logfile: %s -- %s", path, strerror(errno)); |
|
|
|
f2b_log_msg(log_error, "can't open logfile: %s -- %s", path, strerror(errno)); |
|
|
|
return; |
|
|
|
break; |
|
|
|
} else { |
|
|
|
case log_syslog: |
|
|
|
dest = log_stderr; |
|
|
|
openlog("f2b", LOG_CONS, LOG_DAEMON); |
|
|
|
logfile = stderr; |
|
|
|
break; |
|
|
|
|
|
|
|
case log_stderr: |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
logfile = stderr; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|