tags:

views:

183

answers:

1

The glib GLogLevelFlags enum is defined as:

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;

Is it possible for the default handler to receive, for example, (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_DEBUG) as its log level? Is this well-defined according to glib's API guarentees?

+1  A: 

Yes - it is. Seeing as G_LOG_LEVEL_MASK is defined as a bitwise mask with all bits but 0 and 1 set, and

  g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
                 | G_LOG_FLAG_RECURSION, my_log_handler, NULL);

is used as an example for adding a log handler for all messages from GLib, combining log levels is fine.

Also, consider the following quote for g_log_set_handler:

Sets the log handler for a domain and a set of log levels

Finally, see this tutorial, which, among other things, states:

The GLogLevelFlags parameter is an enum of bit flags that define the character and specific channel of a logging message. The three you'll most likely use with logging handlers are G_LOG_LEVEL_MESSAGE, G_LOG_LEVEL_WARNING, and G_LOG_LEVEL_ERROR. Since they are bit flags, you can use a binary OR operator to combine more than one channel into a single handler.

ASk
Yes, those are talking about setting up handlers, but it wouldn't seem to make sense for a specific message to belong to multiple channels, I wouldn't think?
bdonlan
ASk