Function

GLiblog_writer_default_would_drop

since: 2.68

Declaration

gboolean
g_log_writer_default_would_drop (
  GLogLevelFlags log_level,
  const char* log_domain
)

Description

Check whether g_log_writer_default() and g_log_default_handler() would ignore a message with the given domain and level.

As with g_log_default_handler(), this function drops debug and informational messages unless their log domain (or all) is listed in the space-separated G_MESSAGES_DEBUG environment variable.

This can be used when implementing log writers with the same filtering behaviour as the default, but a different destination or output format:

  if (g_log_writer_default_would_drop (log_level, log_domain))
    return G_LOG_WRITER_HANDLED;

or to skip an expensive computation if it is only needed for a debugging message, and G_MESSAGES_DEBUG is not set:

  if (!g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, G_LOG_DOMAIN))
    {
      gchar *result = expensive_computation (my_object);

      g_debug ("my_object result: %s", result);
      g_free (result);
    }

Available since: 2.68

Parameters

log_level

Type: GLogLevelFlags

Log level, either from GLogLevelFlags, or a user-defined level.

log_domain

Type: const char*

Log domain.

The argument can be NULL.
The data is owned by the caller of the function.
The value is a NUL terminated UTF-8 string.

Return value

Type: gboolean

TRUE if the log message would be dropped by GLib’s default log handlers.