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.
This commit is contained in:
parent
a5348a3786
commit
4c967a6ba2
15
src/log.c
15
src/log.c
@ -64,10 +64,25 @@ static const char *log_date(void)
|
|||||||
return buf;
|
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)
|
void initLog(const int verbose)
|
||||||
{
|
{
|
||||||
ConfigParam *param;
|
ConfigParam *param;
|
||||||
|
|
||||||
|
g_log_set_default_handler(mpd_log_func, NULL);
|
||||||
|
|
||||||
/* unbuffer stdout, stderr is unbuffered by default, leave it */
|
/* unbuffer stdout, stderr is unbuffered by default, leave it */
|
||||||
setvbuf(stdout, (char *)NULL, _IONBF, 0);
|
setvbuf(stdout, (char *)NULL, _IONBF, 0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user