Is it possible for the default protocol handler in glib to go through multiple log levels?

The glib glogLevelFlags enumeration 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 e.g. (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_DEBUG) as the log level? Is this well defined according to the glib API?

0


a source to share


1 answer


Yes it is. Seeing as is G_LOG_LEVEL_MASK

defined as a bitwise mask with all bits, but 0 and 1 is set, and

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

      

used as an example to add a log handler for all messages from GLib, the combination of log levels is fine.

Also consider the following quote for g_log_set_handler

:



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

Finally, see this tutorial , which, by the way, reads:

The GLogLevelFlags parameter is an enumeration of bit flags that identify the symbol and specific channel of the registration message. The three that you are most likely to 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 the binary OR operator to combine more than one channel into one handler.

+2


a source







All Articles