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

Loading…
Cancel
Save