Revert accidental commit
[platform/upstream/glib.git] / docs / reference / glib / tmpl / messages.sgml
1 <!-- ##### SECTION Title ##### -->
2 Message Logging
3
4 <!-- ##### SECTION Short_Description ##### -->
5 versatile support for logging messages with different levels of importance.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 These functions provide support for logging error messages or messages 
10 used for debugging. 
11 </para>
12
13 <para>
14 There are several built-in levels of messages, defined in #GLogLevelFlags.
15 These can be extended with user-defined levels.
16 </para>
17
18 <!-- ##### SECTION See_Also ##### -->
19 <para>
20
21 </para>
22
23 <!-- ##### SECTION Stability_Level ##### -->
24
25
26 <!-- ##### MACRO G_LOG_DOMAIN ##### -->
27 <para>
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.
33 </para>
34 <para>
35 For example, GTK+ uses this in its Makefile.am:
36 </para>
37 <informalexample><programlisting>
38 INCLUDES = -DG_LOG_DOMAIN=\"Gtk\"
39 </programlisting></informalexample>
40
41
42
43 <!-- ##### MACRO G_LOG_FATAL_MASK ##### -->
44 <para>
45 GLib log levels that are considered fatal by default.
46 </para>
47
48
49
50 <!-- ##### MACRO G_LOG_LEVEL_USER_SHIFT ##### -->
51 <para>
52 Log level shift offset for user defined log levels (0-7 are used by GLib).
53 </para>
54
55
56
57 <!-- ##### USER_FUNCTION GLogFunc ##### -->
58 <para>
59 Specifies the prototype of log handler functions.
60 </para>
61
62 @log_domain: the log domain of the message.
63 @log_level: the log level of the message (including the fatal and recursion
64 flags).
65 @message: the message to process.
66 @user_data: user data, set in g_log_set_handler().
67
68
69 <!-- ##### ENUM GLogLevelFlags ##### -->
70 <para>
71 Flags specifying the level of log messages.
72 </para>
73
74 @G_LOG_FLAG_RECURSION: 
75 @G_LOG_FLAG_FATAL: 
76 @G_LOG_LEVEL_ERROR: 
77 @G_LOG_LEVEL_CRITICAL: 
78 @G_LOG_LEVEL_WARNING: 
79 @G_LOG_LEVEL_MESSAGE: 
80 @G_LOG_LEVEL_INFO: 
81 @G_LOG_LEVEL_DEBUG: 
82 @G_LOG_LEVEL_MASK: 
83
84 <!-- ##### FUNCTION g_log ##### -->
85 <para>
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.
89 </para>
90
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()
94 documentation.
95 @Varargs: the parameters to insert into the format string.
96
97
98 <!-- ##### FUNCTION g_logv ##### -->
99 <para>
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.
103 </para>
104
105 @log_domain: the log domain.
106 @log_level: the log level.
107 @format: the message format. See the printf()
108 documentation.
109 @args: the parameters to insert into the format string.
110
111
112 <!-- ##### MACRO g_message ##### -->
113 <para>
114 A convenience function/macro to log a normal message.
115 </para>
116
117 @...: format string, followed by parameters to insert into the format string (as with printf())
118
119 @...:
120
121 @...:
122
123 @...: 
124
125
126 <!-- ##### MACRO g_warning ##### -->
127 <para>
128 A convenience function/macro to log a warning message.
129 </para>
130
131 @...: format string, followed by parameters to insert into the format string (as with printf())
132
133 @...:
134
135 @...:
136
137 @...: 
138
139
140 <!-- ##### MACRO g_critical ##### -->
141 <para>
142 Logs a "critical warning" (#G_LOG_LEVEL_CRITICAL). It's more or less
143 application-defined what constitutes a critical vs. a regular
144 warning. You could call g_log_set_always_fatal() to make critical
145 warnings exit the program, then use g_critical() for fatal errors, for
146 example.
147 </para>
148
149 @...: format string, followed by parameters to insert into the format string (as with printf())
150
151 @...:
152
153 @...:
154
155 @...: 
156
157
158 <!-- ##### MACRO g_error ##### -->
159 <para>
160 A convenience function/macro to log an error message.
161 Error messages are always fatal, resulting in a call to
162 abort() to terminate the application.
163 This function will result in a core dump; don't use it for errors you
164 expect. Using this function indicates a bug in your program, i.e. an
165 assertion failure.
166 </para>
167
168 @...: format string, followed by parameters to insert into the format string (as with printf())
169
170 @...:
171
172 @...:
173
174 @...: 
175
176
177 <!-- ##### MACRO g_debug ##### -->
178 <para>
179 A convenience function/macro to log a debug message.
180 </para>
181
182 @...: format string, followed by parameters to insert into the format string (as with printf())
183
184 @...:
185
186 @...:
187
188 @...: 
189 @Since: 2.6
190
191
192 <!-- ##### FUNCTION g_log_set_handler ##### -->
193 <para>
194 Sets the log handler for a domain and a set of log levels.
195 To handle fatal and recursive messages the @log_levels parameter
196 must be combined with the #G_LOG_FLAG_FATAL and #G_LOG_FLAG_RECURSION 
197 bit flags.
198 </para>
199 <para>
200 Note that since the #G_LOG_LEVEL_ERROR log level is always fatal, if 
201 you want to set a handler for this log level you must combine it with 
202 #G_LOG_FLAG_FATAL.
203 </para>
204
205 <example>
206 <title>Adding a log handler for all warning messages in the default 
207 (application) domain</title>
208 <programlisting>
209   g_log_set_handler (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL
210                      | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
211 </programlisting>
212 </example>
213
214 <example>
215 <title>Adding a log handler for all critical messages from GTK+</title>
216 <programlisting>
217   g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL
218                      | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
219 </programlisting>
220 </example>
221
222 <example>
223 <title>Adding a log handler for <emphasis>all</emphasis> messages from 
224 GLib</title>
225 <programlisting>
226   g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
227                      | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
228 </programlisting>
229 </example>
230
231 @log_domain: the log domain, or %NULL for the default "" application domain.
232 @log_levels: the log levels to apply the log handler for. To handle fatal
233 and recursive messages as well, combine the log levels with the
234 #G_LOG_FLAG_FATAL and #G_LOG_FLAG_RECURSION bit flags.
235 @log_func: the log handler function.
236 @user_data: data passed to the log handler.
237 @Returns: the id of the new handler.
238
239
240 <!-- ##### FUNCTION g_log_remove_handler ##### -->
241 <para>
242 Removes the log handler.
243 </para>
244
245 @log_domain: the log domain.
246 @handler_id: the id of the handler, which was returned in g_log_set_handler().
247
248
249 <!-- ##### FUNCTION g_log_set_always_fatal ##### -->
250 <para>
251 Sets the message levels which are always fatal, in any log domain.
252 When a message with any of these levels is logged the program terminates.
253 You can only set the levels defined by GLib to be fatal.
254 %G_LOG_LEVEL_ERROR is always fatal.
255 </para>
256
257 @fatal_mask: the mask containing bits set for each level of error which is
258 to be fatal.
259 @Returns: the old fatal mask.
260
261
262 <!-- ##### FUNCTION g_log_set_fatal_mask ##### -->
263 <para>
264 Sets the log levels which are fatal in the given domain.
265 %G_LOG_LEVEL_ERROR is always fatal.
266 </para>
267
268 @log_domain: the log domain.
269 @fatal_mask: the new fatal mask.
270 @Returns: the old fatal mask for the log domain.
271
272
273 <!-- ##### FUNCTION g_log_default_handler ##### -->
274 <para>
275 The default log handler set up by GLib; g_log_set_default_handler() 
276 allows to install an alternate default log handler.
277 This is used if no log handler has been set for the particular log domain
278 and log level combination. It outputs the message to stderr or stdout
279 and if the log level is fatal it calls abort().
280 </para>
281 <para>
282 stderr is used for levels %G_LOG_LEVEL_ERROR, %G_LOG_LEVEL_CRITICAL,
283 %G_LOG_LEVEL_WARNING and %G_LOG_LEVEL_MESSAGE. stdout is used for the rest.
284 </para>
285
286 @log_domain: the log domain of the message.
287 @log_level: the level of the message.
288 @message: the message.
289 @unused_data: data passed from g_log() which is unused.
290
291
292 <!-- ##### FUNCTION g_log_set_default_handler ##### -->
293 <para>
294 Installs a default log handler which is used is used if no 
295 log handler has been set for the particular log domain
296 and log level combination. By default, GLib uses 
297 g_log_default_handler() as default log handler.
298 </para>
299
300 @log_func: the log handler function.
301 @user_data: data passed to the log handler.
302 @Returns: the previous default log handler
303 @Since: 2.6
304
305