GNOME Bugzilla – Bug 622433
g_log_set_default_handler does not return the user_data for the previous handler
Last modified: 2017-10-06 11:27:56 UTC
If a default handler is set with g_log_set_default_handler with associated user_data, a new call to g_log_set_default_handler will return a pointer to the previous handler but not to the associated user_data to that handler. With the current API is not possible to stack log handlers that use user_data.
Something like this would be nice: > GLogFunc* old_handler = NULL; > gpointer old_data = NULL; > > old_handler = g_log_override_default_handler (new_handler, new_data, &old_data); I'm just not sure about the name; maybe use g_log_set_default_handler_full()?
The advice is now to use the new logging API, and install a writer function using g_log_set_writer_func(), instead of using a log handler function. g_log_set_writer_func() deliberately doesn’t return the old log writer function, because there should be none — it’s intended that the end application calls g_log_set_writer_func() exactly once, and libraries don’t call it at all. g_log_set_writer_func() takes a GDestroyNotify so the user_data can be freed at the end of its lifetime.