From 4dcb22c14ac2e633bdf5f6a03576589ed1245a6d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 5 Sep 2004 05:46:33 +0000 Subject: [PATCH] New function to install an alternate default log handler. (#66387, Darin Sun Sep 5 01:46:11 2004 Matthias Clasen * glib/glib.def: * glib/gmessages.h: * glib/gmessages.c (g_log_set_default_handler): New function to install an alternate default log handler. (#66387, Darin Adler) --- ChangeLog | 8 +++++++ ChangeLog.pre-2-10 | 8 +++++++ ChangeLog.pre-2-12 | 8 +++++++ ChangeLog.pre-2-6 | 8 +++++++ ChangeLog.pre-2-8 | 8 +++++++ docs/reference/ChangeLog | 5 ++++ docs/reference/glib/glib-sections.txt | 1 + docs/reference/glib/tmpl/messages.sgml | 32 ++++++++++++++++++++------ glib/glib.def | 1 + glib/gmessages.c | 22 ++++++++++++++++-- glib/gmessages.h | 2 ++ 11 files changed, 94 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03bc2de0..25ad832a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sun Sep 5 01:46:11 2004 Matthias Clasen + + * glib/glib.def: + * glib/gmessages.h: + * glib/gmessages.c (g_log_set_default_handler): New + function to install an alternate default log + handler. (#66387, Darin Adler) + 2004-09-03 Tor Lillqvist * glib/glib.def: Update. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 03bc2de0..25ad832a 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +Sun Sep 5 01:46:11 2004 Matthias Clasen + + * glib/glib.def: + * glib/gmessages.h: + * glib/gmessages.c (g_log_set_default_handler): New + function to install an alternate default log + handler. (#66387, Darin Adler) + 2004-09-03 Tor Lillqvist * glib/glib.def: Update. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 03bc2de0..25ad832a 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +Sun Sep 5 01:46:11 2004 Matthias Clasen + + * glib/glib.def: + * glib/gmessages.h: + * glib/gmessages.c (g_log_set_default_handler): New + function to install an alternate default log + handler. (#66387, Darin Adler) + 2004-09-03 Tor Lillqvist * glib/glib.def: Update. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 03bc2de0..25ad832a 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +Sun Sep 5 01:46:11 2004 Matthias Clasen + + * glib/glib.def: + * glib/gmessages.h: + * glib/gmessages.c (g_log_set_default_handler): New + function to install an alternate default log + handler. (#66387, Darin Adler) + 2004-09-03 Tor Lillqvist * glib/glib.def: Update. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 03bc2de0..25ad832a 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +Sun Sep 5 01:46:11 2004 Matthias Clasen + + * glib/glib.def: + * glib/gmessages.h: + * glib/gmessages.c (g_log_set_default_handler): New + function to install an alternate default log + handler. (#66387, Darin Adler) + 2004-09-03 Tor Lillqvist * glib/glib.def: Update. diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index cbdaea65..7a54b5b8 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +Sun Sep 5 01:44:23 2004 Matthias Clasen + + * glib/glib-sections.txt: + * glib/tmpl/messages.sgml: Document g_log_set_default_handler(). + Wed Sep 1 20:27:59 2004 Matthias Clasen * glib/glib-sections.txt: Add g_date_get_iso8601_week_of_year. diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index cabafd4c..f5eb2c27 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -853,6 +853,7 @@ g_log_remove_handler g_log_set_always_fatal g_log_set_fatal_mask g_log_default_handler +g_log_set_default_handler
diff --git a/docs/reference/glib/tmpl/messages.sgml b/docs/reference/glib/tmpl/messages.sgml index f197c622..7575a6cb 100644 --- a/docs/reference/glib/tmpl/messages.sgml +++ b/docs/reference/glib/tmpl/messages.sgml @@ -6,7 +6,8 @@ versatile support for logging messages with different levels of importance. -These functions provide support for logging error messages or messages used for debugging. +These functions provide support for logging error messages or messages +used for debugging. @@ -159,15 +160,18 @@ A convenience function/macro to log a debug message. Sets the log handler for a domain and a set of log levels. To handle fatal and recursive messages the @log_levels parameter -must be combined with the #G_LOG_FLAG_FATAL and #G_LOG_FLAG_RECURSION bit flags. +must be combined with the #G_LOG_FLAG_FATAL and #G_LOG_FLAG_RECURSION +bit flags. -Note that since the #G_LOG_LEVEL_ERROR log level is always fatal, if you want -to set a handler for this log level you must combine it with #G_LOG_FLAG_FATAL. +Note that since the #G_LOG_LEVEL_ERROR log level is always fatal, if +you want to set a handler for this log level you must combine it with +#G_LOG_FLAG_FATAL. -Adding a log handler for all warning messages in the default (application) domain +Adding a log handler for all warning messages in the default +(application) domain g_log_set_handler (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, my_log_handler, NULL); @@ -183,7 +187,8 @@ to set a handler for this log level you must combine it with #G_LOG_FLAG_FATAL. -Adding a log handler for <emphasis>all</emphasis> messages from GLib +Adding a log handler for <emphasis>all</emphasis> messages from +GLib g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, my_log_handler, NULL); @@ -234,7 +239,8 @@ Sets the log levels which are fatal in the given domain. -The default log handler. +The default log handler set up by GLib; g_log_set_default_handler() +allows to install an alternate default log handler. This is used if no log handler has been set for the particular log domain and log level combination. It outputs the message to stderr or stdout and if the log level is fatal it calls abort(). @@ -243,10 +249,22 @@ and if the log level is fatal it calls abort(). stderr is used for levels %G_LOG_LEVEL_ERROR, %G_LOG_LEVEL_CRITICAL, and %G_LOG_LEVEL_WARNING. stdout is used for the rest. + @log_domain: the log domain of the message. @log_level: the level of the message. @message: the message. @unused_data: data passed from g_log() which is unused. + + +Installs a default log handler which is used is used if no +log handler has been set for the particular log domain +and log level combination. By default, GLib uses +g_log_default_handler() as default log handler. + +@log_func: the log handler function. +@user_data: data passed to the log handler. +@Returns: the previous default log handler +@Since: 2.6 diff --git a/glib/glib.def b/glib/glib.def index f77982da..f2639f97 100644 --- a/glib/glib.def +++ b/glib/glib.def @@ -317,6 +317,7 @@ EXPORTS g_log_default_handler g_log_remove_handler g_log_set_always_fatal + g_log_set_default_handler g_log_set_fatal_mask g_log_set_handler g_logv diff --git a/glib/gmessages.c b/glib/gmessages.c index fffd4027..00db52dd 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -81,7 +81,8 @@ static GPrintFunc glib_print_func = NULL; static GPrintFunc glib_printerr_func = NULL; static GPrivate *g_log_depth = NULL; static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG; - +static GLogFunc default_log_func = g_log_default_handler; +static gpointer default_log_data = NULL; /* --- functions --- */ #ifdef G_OS_WIN32 @@ -284,7 +285,9 @@ g_log_domain_get_handler_L (GLogDomain *domain, handler = handler->next; } } - return g_log_default_handler; + + *data = default_log_data; + return default_log_func; } GLogLevelFlags @@ -375,6 +378,21 @@ g_log_set_handler (const gchar *log_domain, return handler_id; } +GLogFunc +g_log_set_default_handler (GLogFunc log_func, + gpointer user_data) +{ + GLogFunc old_log_func; + + g_mutex_lock (g_messages_lock); + old_log_func = default_log_func; + default_log_func = log_func; + default_log_data = user_data; + g_mutex_unlock (g_messages_lock); + + return old_log_func; +} + void g_log_remove_handler (const gchar *log_domain, guint handler_id) diff --git a/glib/gmessages.h b/glib/gmessages.h index c3606291..ab76c4c4 100644 --- a/glib/gmessages.h +++ b/glib/gmessages.h @@ -88,6 +88,8 @@ void g_log_default_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data); +GLogFunc g_log_set_default_handler (GLogFunc log_func, + gpointer user_data); void g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, -- 2.34.1