aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-28 19:48:53 +0100
committerMax Kellermann <max@duempel.org>2008-12-28 19:48:53 +0100
commitc6cb611065ab1260ff07b939a9fafa4027fcc5c8 (patch)
tree8ec6f0021a3743348fb7eace7cdef37cd5f5ac96 /src/log.c
parentd70c2e228517c60506a98b38d90cc3e939b6331c (diff)
downloadmpd-c6cb611065ab1260ff07b939a9fafa4027fcc5c8.tar.gz
mpd-c6cb611065ab1260ff07b939a9fafa4027fcc5c8.tar.xz
mpd-c6cb611065ab1260ff07b939a9fafa4027fcc5c8.zip
log: moved code to log_init_file()
Added log_init_file() and log_init_stdout(), preparing for other logging targets.
Diffstat (limited to '')
-rw-r--r--src/log.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/log.c b/src/log.c
index 38e0a8f10..fdb470447 100644
--- a/src/log.c
+++ b/src/log.c
@@ -64,9 +64,9 @@ static const char *log_date(void)
}
static void
-mpd_log_func(const gchar *log_domain,
- G_GNUC_UNUSED GLogLevelFlags log_level,
- const gchar *message, G_GNUC_UNUSED gpointer user_data)
+file_log_func(const gchar *log_domain,
+ G_GNUC_UNUSED GLogLevelFlags log_level,
+ const gchar *message, G_GNUC_UNUSED gpointer user_data)
{
char *converted;
@@ -93,6 +93,12 @@ mpd_log_func(const gchar *log_domain,
g_free(converted);
}
+static void
+log_init_stdout(void)
+{
+ g_log_set_default_handler(file_log_func, NULL);
+}
+
static int
open_log_file(void)
{
@@ -101,6 +107,18 @@ open_log_file(void)
return open(out_filename, O_CREAT | O_WRONLY | O_APPEND, 0666);
}
+static void
+log_init_file(const char *path, unsigned line)
+{
+ out_filename = path;
+ out_fd = open_log_file();
+ if (out_fd < 0)
+ FATAL("problem opening log file \"%s\" (config line %u) for "
+ "writing\n", path, line);
+
+ g_log_set_default_handler(file_log_func, NULL);
+}
+
static inline GLogLevelFlags
parse_log_level(const char *value, unsigned line)
{
@@ -121,23 +139,17 @@ void log_init(bool verbose, bool use_stdout)
g_get_charset(&log_charset);
- g_log_set_default_handler(mpd_log_func, NULL);
-
if (verbose)
log_threshold = G_LOG_LEVEL_DEBUG;
else if ((param = getConfigParam(CONF_LOG_LEVEL)) != NULL)
log_threshold = parse_log_level(param->value, param->line);
- if (use_stdout)
- return;
-
- param = parseConfigFilePath(CONF_LOG_FILE, 1);
- out_filename = param->value;
-
- out_fd = open_log_file();
- if (out_fd < 0)
- FATAL("problem opening log file \"%s\" (config line %i) for "
- "writing\n", param->value, param->line);
+ if (use_stdout) {
+ log_init_stdout();
+ } else {
+ param = parseConfigFilePath(CONF_LOG_FILE, 1);
+ log_init_file(param->value, param->line);
+ }
}
void setup_log_output(bool use_stdout)