Re: Bug in glib in g_logv



On Thu, 8 Jun 2000, Jonas Bulow wrote:

> If I want to register my own log handler for a specific level and domain
> I thought I should write somethine like this:
> 
> g_log_set_handler(MY_LOG_DOMAIN, G_LOG_LEVEL_ERROR,
> my_error_log_handler, NULL);  
> 
> But g_log_domain_get_handler is not able to find my log handler in
> g_logv if I don't write the previous line as
> 
> g_log_set_handler(MY_LOG_DOMAIN, G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
> my_error_log_handler, NULL);  
> 
> If this is the desired behaviour, maybe it should be mentioned in the
> reference manual.

it might not be mentioned in the reference manual (which is why i'm cc-ing
gtk-doc-list@gnome.org), but the enum definition in glib.h explicitely
states this:

/* Glib log levels and flags.
 */
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;

> If you change line 383 in gmessages.c from
>   log_func = g_log_domain_get_handler (domain, test_level, &data);
> to:
>   log_func = g_log_domain_get_handler (domain, log_level, &data);
> 
> , I think it would be possible to register a log handler to a level even
> if it is considered fatal. 

that would fail for handlers at a certain log_level (say G_LOG_LEVEL_INFO)
and messages being logged at multiple log levels (say G_LOG_LEVEL_INFO |
G_LOG_LEVEL_DEBUG). it also falls short for finding a handler that
handles G_LOG_FLAG_RECURSION. if at all, we had to do this as:
  log_func = g_log_domain_get_handler (domain,
                                       test_level & ~(G_LOG_FLAG_RECURSION |
                                                      G_LOG_FLAG_FATAL),
                                       &data);
but then we'd loose the ability to have special handlers for fatal cases
of arbitrary log levels.

if you want your handler to catch all messages in your domain, simply always
add (G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL) to the log_levels mask when
calling g_log_set_handler().

> 
> I'm not on this mailing list so please CC me your answers!
> 
> regards,
> 	jonas
> 

---
ciaoTJ





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]