Browse Source

+ add 'stdout' variant for log destination

master
Alex 'AdUser' Z 7 months ago
parent
commit
ce0a2a8a7a
  1. 1
      configs/f2b.conf.in
  2. 14
      src/log.c
  3. 2
      src/log.h

1
configs/f2b.conf.in

@ -2,6 +2,7 @@
includes = ${CMAKE_INSTALL_FULL_SYSCONFDIR}/f2b/conf-enabled
pidfile = /var/run/f2b.pid
statedir = ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/f2b
; valid destinations: stdout, stderr, syslog, file (logfile option should be set)
logdest = syslog
loglevel = info
logfile = /var/log/f2b.log

14
src/log.c

@ -10,7 +10,12 @@
#include <sys/syslog.h>
static log_msgtype_t minlevel = log_info;
static enum { log_stderr = 0, log_file = 1, log_syslog = 2 } dest = log_stderr;
static enum {
log_stderr = 0,
log_stdout = 1,
log_file = 2,
log_syslog = 3
} dest = log_stderr;
static FILE *logfile = NULL;
static const char *loglevels[] = {
@ -79,6 +84,13 @@ void f2b_log_set_level(const char *level) {
if (strcmp(level, "fatal") == 0) { minlevel = log_fatal; return; }
}
void f2b_log_to_stdout() {
if (logfile && logfile != stdout)
fclose(logfile);
dest = log_stdout;
logfile = stdout;
}
void f2b_log_to_stderr() {
if (logfile && logfile != stderr)
fclose(logfile);

2
src/log.h

@ -52,6 +52,8 @@ void f2b_log_set_level(const char *level);
* @param path Path for logfile
*/
void f2b_log_to_file (const char *path);
/** @brief Use logging to stdout */
void f2b_log_to_stdout();
/** @brief Use logging to stderr */
void f2b_log_to_stderr();
/** @brief Use logging to syslog */

Loading…
Cancel
Save