aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-05 18:38:55 +0100
committerMax Kellermann <max@duempel.org>2008-11-05 18:38:55 +0100
commit4c967a6ba26057ffb4fd9822a7b77f8af64f734f (patch)
tree27464a0a7ef6f696f3fa89f5b8333bd2baf8408c /src/log.c
parenta5348a3786f5d7c708019c2e853085de7f26f260 (diff)
downloadmpd-4c967a6ba26057ffb4fd9822a7b77f8af64f734f.tar.gz
mpd-4c967a6ba26057ffb4fd9822a7b77f8af64f734f.tar.xz
mpd-4c967a6ba26057ffb4fd9822a7b77f8af64f734f.zip
log: provide a GLib logging handler
Install a default handler which writes to stdout or stderr, and prepends a time stamp. This looks just like the 0.13.x logger.
Diffstat (limited to '')
-rw-r--r--src/log.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
index 6070f5e44..da2361533 100644
--- a/src/log.c
+++ b/src/log.c
@@ -64,10 +64,25 @@ static const char *log_date(void)
return buf;
}
+static void
+mpd_log_func(G_GNUC_UNUSED const gchar *log_domain,
+ G_GNUC_UNUSED GLogLevelFlags log_level,
+ const gchar *message, G_GNUC_UNUSED gpointer user_data)
+{
+ FILE *file = log_level <= G_LOG_LEVEL_WARNING
+ ? stderr : stdout;
+
+ fprintf(file, "%s%s",
+ stdout_mode ? "" : log_date(),
+ message);
+}
+
void initLog(const int verbose)
{
ConfigParam *param;
+ g_log_set_default_handler(mpd_log_func, NULL);
+
/* unbuffer stdout, stderr is unbuffered by default, leave it */
setvbuf(stdout, (char *)NULL, _IONBF, 0);