From c3a5222f84ad4d34852ce83889ab2b363823b1b8 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Fri, 8 May 2009 18:17:01 +0200 Subject: [PATCH] Log libevent errors through our own logger --- src/logger.c | 33 ++++++++++++++++++++++++++++++++- src/logger.h | 9 +++++++-- src/main.c | 3 +++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/logger.c b/src/logger.c index fded000d..d2b2d8d2 100644 --- a/src/logger.c +++ b/src/logger.c @@ -23,6 +23,8 @@ #include #include +#include + #include "logger.h" @@ -32,7 +34,7 @@ static int threshold; static int console; static char *logfilename; static FILE *logfile; -static char *labels[] = { "config", "daap", "db", "httpd", "main", "mdns", "misc", "parse", "rsp", "scan", "xcode", "lock" }; +static char *labels[] = { "config", "daap", "db", "httpd", "main", "mdns", "misc", "parse", "rsp", "scan", "xcode", "event", "lock" }; static int @@ -112,6 +114,35 @@ DPRINTF(int severity, int domain, char *fmt, ...) pthread_mutex_unlock(&logger_lck); } +void +logger_libevent(int severity, const char *msg) +{ + switch (severity) + { + case _EVENT_LOG_DEBUG: + severity = E_DBG; + break; + + case _EVENT_LOG_ERR: + severity = E_LOG; + break; + + case _EVENT_LOG_WARN: + severity = E_WARN; + break; + + case _EVENT_LOG_MSG: + severity = E_INFO; + break; + + default: + severity = E_LOG; + break; + } + + DPRINTF(severity, L_EVENT, "%s\n", msg); +} + void logger_reinit(void) { diff --git a/src/logger.h b/src/logger.h index 2c939101..319406bd 100644 --- a/src/logger.h +++ b/src/logger.h @@ -14,10 +14,12 @@ #define L_RSP 8 #define L_SCAN 9 #define L_XCODE 10 +/* libevent logging */ +#define L_EVENT 11 /* Will go away */ -#define L_LOCK 11 -#define N_LOGDOMAINS 12 +#define L_LOCK 12 +#define N_LOGDOMAINS 13 /* Severities */ #define E_FATAL 0 @@ -31,6 +33,9 @@ void DPRINTF(int severity, int domain, char *fmt, ...); +void +logger_libevent(int severity, const char *msg); + void logger_reinit(void); diff --git a/src/main.c b/src/main.c index b327d744..c6994cbd 100644 --- a/src/main.c +++ b/src/main.c @@ -447,6 +447,9 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } + /* Set up libevent logging callback */ + event_set_log_callback(logger_libevent); + DPRINTF(E_LOG, L_MAIN, "Firefly Version %s taking off\n", VERSION); /* initialize ffmpeg */