1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 versatile support for logging messages with different levels of importance.
7 <!-- ##### SECTION Long_Description ##### -->
9 These functions provide support for logging error messages or messages
14 There are several built-in levels of messages, defined in #GLogLevelFlags.
15 These can be extended with user-defined levels.
18 <!-- ##### SECTION See_Also ##### -->
23 <!-- ##### SECTION Stability_Level ##### -->
26 <!-- ##### MACRO G_LOG_DOMAIN ##### -->
28 Defines the log domain.
29 For applications, this is typically left as the default %NULL (or "") domain.
30 Libraries should define this so that any messages which they log can
31 be differentiated from messages from other libraries and application code.
32 But be careful not to define it in any public header files.
35 For example, GTK+ uses this in its Makefile.am:
37 <informalexample><programlisting>
38 INCLUDES = -DG_LOG_DOMAIN=\"Gtk\"
39 </programlisting></informalexample>
43 <!-- ##### MACRO G_LOG_FATAL_MASK ##### -->
45 GLib log levels that are considered fatal by default.
50 <!-- ##### MACRO G_LOG_LEVEL_USER_SHIFT ##### -->
52 Log level shift offset for user defined log levels (0-7 are used by GLib).
57 <!-- ##### USER_FUNCTION GLogFunc ##### -->
59 Specifies the prototype of log handler functions.
62 @log_domain: the log domain of the message.
63 @log_level: the log level of the message (including the fatal and recursion
65 @message: the message to process.
66 @user_data: user data, set in g_log_set_handler().
69 <!-- ##### ENUM GLogLevelFlags ##### -->
71 Flags specifying the level of log messages.
74 @G_LOG_FLAG_RECURSION:
77 @G_LOG_LEVEL_CRITICAL:
84 <!-- ##### FUNCTION g_log ##### -->
86 Logs an error or debugging message.
87 If the log level has been set as fatal, the abort()
88 function is called to terminate the program.
91 @log_domain: the log domain, usually #G_LOG_DOMAIN.
92 @log_level: the log level, either from #GLogLevelFlags or a user-defined level.
93 @format: the message format. See the printf()
95 @Varargs: the parameters to insert into the format string.
98 <!-- ##### FUNCTION g_logv ##### -->
100 Logs an error or debugging message.
101 If the log level has been set as fatal, the abort()
102 function is called to terminate the program.
105 @log_domain: the log domain.
106 @log_level: the log level.
107 @format: the message format. See the printf()
109 @args: the parameters to insert into the format string.
112 <!-- ##### MACRO g_message ##### -->
114 A convenience function/macro to log a normal message.
117 @...: format string, followed by parameters to insert into the format string (as with printf())
128 <!-- ##### MACRO g_warning ##### -->
130 A convenience function/macro to log a warning message.
133 @...: format string, followed by parameters to insert into the format string (as with printf())
144 <!-- ##### MACRO g_critical ##### -->
146 Logs a "critical warning" (#G_LOG_LEVEL_CRITICAL). It's more or less
147 application-defined what constitutes a critical vs. a regular
148 warning. You could call g_log_set_always_fatal() to make critical
149 warnings exit the program, then use g_critical() for fatal errors, for
153 @...: format string, followed by parameters to insert into the format string (as with printf())
164 <!-- ##### MACRO g_error ##### -->
166 A convenience function/macro to log an error message.
167 Error messages are always fatal, resulting in a call to
168 abort() to terminate the application.
169 This function will result in a core dump; don't use it for errors you
170 expect. Using this function indicates a bug in your program, i.e. an
174 @...: format string, followed by parameters to insert into the format string (as with printf())
185 <!-- ##### MACRO g_debug ##### -->
187 A convenience function/macro to log a debug message.
190 @...: format string, followed by parameters to insert into the format string (as with printf())
202 <!-- ##### FUNCTION g_log_set_handler ##### -->
204 Sets the log handler for a domain and a set of log levels.
205 To handle fatal and recursive messages the @log_levels parameter
206 must be combined with the #G_LOG_FLAG_FATAL and #G_LOG_FLAG_RECURSION
210 Note that since the #G_LOG_LEVEL_ERROR log level is always fatal, if
211 you want to set a handler for this log level you must combine it with
216 <title>Adding a log handler for all warning messages in the default
217 (application) domain</title>
219 g_log_set_handler (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL
220 | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
225 <title>Adding a log handler for all critical messages from GTK+</title>
227 g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL
228 | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
233 <title>Adding a log handler for <emphasis>all</emphasis> messages from
236 g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
237 | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
241 @log_domain: the log domain, or %NULL for the default "" application domain.
242 @log_levels: the log levels to apply the log handler for. To handle fatal
243 and recursive messages as well, combine the log levels with the
244 #G_LOG_FLAG_FATAL and #G_LOG_FLAG_RECURSION bit flags.
245 @log_func: the log handler function.
246 @user_data: data passed to the log handler.
247 @Returns: the id of the new handler.
250 <!-- ##### FUNCTION g_log_remove_handler ##### -->
252 Removes the log handler.
255 @log_domain: the log domain.
256 @handler_id: the id of the handler, which was returned in g_log_set_handler().
259 <!-- ##### FUNCTION g_log_set_always_fatal ##### -->
261 Sets the message levels which are always fatal, in any log domain.
262 When a message with any of these levels is logged the program terminates.
263 You can only set the levels defined by GLib to be fatal.
264 %G_LOG_LEVEL_ERROR is always fatal.
267 @fatal_mask: the mask containing bits set for each level of error which is
269 @Returns: the old fatal mask.
272 <!-- ##### FUNCTION g_log_set_fatal_mask ##### -->
274 Sets the log levels which are fatal in the given domain.
275 %G_LOG_LEVEL_ERROR is always fatal.
278 @log_domain: the log domain.
279 @fatal_mask: the new fatal mask.
280 @Returns: the old fatal mask for the log domain.
283 <!-- ##### FUNCTION g_log_default_handler ##### -->
285 The default log handler set up by GLib; g_log_set_default_handler()
286 allows to install an alternate default log handler.
287 This is used if no log handler has been set for the particular log domain
288 and log level combination. It outputs the message to stderr or stdout
289 and if the log level is fatal it calls abort().
292 stderr is used for levels %G_LOG_LEVEL_ERROR, %G_LOG_LEVEL_CRITICAL,
293 %G_LOG_LEVEL_WARNING and %G_LOG_LEVEL_MESSAGE. stdout is used for the rest.
296 @log_domain: the log domain of the message.
297 @log_level: the level of the message.
298 @message: the message.
299 @unused_data: data passed from g_log() which is unused.
302 <!-- ##### FUNCTION g_log_set_default_handler ##### -->
304 Installs a default log handler which is used is used if no
305 log handler has been set for the particular log domain
306 and log level combination. By default, GLib uses
307 g_log_default_handler() as default log handler.
310 @log_func: the log handler function.
311 @user_data: data passed to the log handler.
312 @Returns: the previous default log handler