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.
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.
This has no effect if structured logging is enabled; see Using Structured Logging.
Here is an example for adding a log handler for all warning messages in the default domain:
g_log_set_handler (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSION, my_log_handler, NULL);
This example adds a log handler for all critical messages from GTK+:
g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSION, my_log_handler, NULL);
This example adds a log handler for all messages from GLib:
g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSION, my_log_handler, NULL);
log_domain |
the log domain, or null for the default "" application domain |
log_levels |
the log levels to apply the log handler for. To handle fatal and recursive messages as well, combine the log levels with the g_log_flag_fatal and g_log_flag_recursion bit flags. |
log_func |
the log handler function |
user_data |
data passed to the log handler |
the id of the new handler |