Description
These functions provide support for logging error messages or messages
used for debugging.
There are several built-in levels of messages, defined in GLogLevelFlags.
These can be extended with user-defined levels.
Details
G_LOG_DOMAIN
#define G_LOG_DOMAIN ((gchar*) 0) |
Defines the log domain.
For applications, this is typically left as the default NULL (or "") domain.
Libraries should define this so that any messages which they log can
be differentiated from messages from other libraries and application code.
But be careful not to define it in any public header files.
For example, GTK uses this in its Makefile.am:
g_log_domain_glib
extern const gchar *g_log_domain_glib; |
g_log_domain_gmodule
extern const char *g_log_domain_gmodule; |
G_LOG_FATAL_MASK
#define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR) |
GLib log levels that are considered fatal by default.
G_LOG_LEVEL_USER_SHIFT
#define G_LOG_LEVEL_USER_SHIFT (8) |
Log level shift offset for user defined log levels (0-7 are used by GLib).
GLogFunc ()
Specifies the prototype of log handler functions.
enum GLogLevelFlags
typedef enum
{
/* log flags */
G_LOG_FLAG_RECURSION = 1 << 0,
G_LOG_FLAG_FATAL = 1 << 1,
/* GLib log levels */
G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
G_LOG_LEVEL_CRITICAL = 1 << 3,
G_LOG_LEVEL_WARNING = 1 << 4,
G_LOG_LEVEL_MESSAGE = 1 << 5,
G_LOG_LEVEL_INFO = 1 << 6,
G_LOG_LEVEL_DEBUG = 1 << 7,
G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
} GLogLevelFlags; |
Flags specifying the level of log messages.
g_log ()
Logs an error or debugging message.
If the log level has been set as fatal, the abort()
function is called to terminate the program.
g_logv ()
Logs an error or debugging message.
If the log level has been set as fatal, the abort()
function is called to terminate the program.
g_message()
#define g_message(format, args...) |
A convenience function/macro to log a normal message.
g_warning()
#define g_warning(format, args...) |
A convenience function/macro to log a warning message.
g_error()
#define g_error(format, args...) |
A convenience function/macro to log an error message.
Error messages are always fatal, resulting in a call to
abort() to terminate the application.
g_log_set_handler ()
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_RECURSIVE 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.
Example 1. Adding a log handler for all warning messages
g_log_set_handler (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSIVE, my_log_handler, NULL); |
g_log_remove_handler ()
void g_log_remove_handler (const gchar *log_domain,
guint handler_id); |
Removes the log handler.
g_log_set_always_fatal ()
Sets the message levels which are always fatal, in any log domain.
When a message with any of these levels is logged the program terminates.
You can only set the levels defined by GLib to be fatal.
G_LOG_LEVEL_ERROR is always fatal.
g_log_set_fatal_mask ()
Sets the log levels which are fatal in the given domain.
G_LOG_LEVEL_ERROR is always fatal.
g_log_default_handler ()
The 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().
stderr is used for levels G_LOG_LEVEL_ERROR, G_LOG_LEVEL_CRITICAL, and
G_LOG_LEVEL_WARNING. stdout is used for the rest.
(On the Windows platform, stdout is always used.)
g_set_error_handler ()
Sets the function to be called to handle error messages.
This function is deprecated in favour of the new logging facilities.
g_set_warning_handler ()
Sets the function to be called to handle warning messages.
This function is deprecated in favour of the new logging facilities.
g_set_message_handler ()
Sets the function to be called to handle messages.
This function is deprecated in favour of the new logging facilities.