Browse Source

* work on logs

master
Alex 'AdUser' Z 9 years ago
parent
commit
d66182605e
  1. 36
      src/log.c
  2. 4
      src/log.h

36
src/log.c

@ -62,24 +62,28 @@ 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_setup(const char *target, const char *path) { void f2b_log_to_stderr() {
if (strcmp(target, "syslog") == 0) { if (logfile && logfile != stderr)
dest = log_syslog; fclose(logfile);
openlog("f2b", LOG_CONS, LOG_DAEMON); dest = log_stderr;
logfile = stderr;
}
void f2b_log_to_file(const char *path) {
FILE *new = NULL;
if (path == NULL || *path == '\0')
return; return;
} else if ((new = fopen(path, "a")) != NULL) {
if (strcmp(target, "file") == 0 && *path != '\0') { if (logfile && logfile != stderr)
dest = log_file;
if (logfile)
fclose(logfile); fclose(logfile);
if ((logfile = fopen(path, "a")) == NULL) dest = log_file;
dest = log_stderr, logfile = stderr; logfile = new;
f2b_log_msg(log_error, "can't open logfile: %s -- %s", path, strerror(errno));
return;
} else {
dest = log_stderr;
logfile = stderr;
} }
}
return; void f2b_log_to_syslog() {
if (logfile && logfile != stderr)
fclose(logfile);
dest = log_syslog;
openlog("f2b", 0 | LOG_PID, LOG_DAEMON);
} }

4
src/log.h

@ -13,6 +13,8 @@ typedef enum {
void f2b_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); void f2b_log_set_level(const char *level);
void f2b_log_setup(const char *target, const char *path); void f2b_log_to_file (const char *path);
void f2b_log_to_stderr();
void f2b_log_to_syslog();
#endif /* F2B_LOG_H_ */ #endif /* F2B_LOG_H_ */

Loading…
Cancel
Save