Commit a8e3f36e authored by Ell's avatar Ell

app: add gimp_log_{set,remove}_handler()

... which set/remove a GLIB log handler for all domains used by
GIMP.

Use the new functions in errors.c, instead of using
g_log_set_handler() directly.

(cherry picked from commit a143bfdf)
parent 7dc9cdf4
......@@ -46,6 +46,7 @@
#include "pdb/gimppdb.h"
#include "errors.h"
#include "gimp-log.h"
#ifdef G_OS_WIN32
#include <windows.h>
......@@ -53,47 +54,13 @@
/* private variables */
static const gchar * const log_domains[] =
{
"Gimp",
"Gimp-Actions",
"Gimp-Base",
"Gimp-Composite",
"Gimp-Config",
"Gimp-Core",
"Gimp-Dialogs",
"Gimp-Display",
"Gimp-File",
"Gimp-GEGL",
"Gimp-GUI",
"Gimp-Menus",
"Gimp-Operations",
"Gimp-PDB",
"Gimp-Paint",
"Gimp-Paint-Funcs",
"Gimp-Plug-In",
"Gimp-Text",
"Gimp-Tools",
"Gimp-Vectors",
"Gimp-Widgets",
"Gimp-XCF",
"LibGimpBase",
"LibGimpColor",
"LibGimpConfig",
"LibGimpMath",
"LibGimpModule",
"LibGimpThumb",
"LibGimpWidgets"
};
static Gimp *the_errors_gimp = NULL;
static gboolean use_debug_handler = FALSE;
static GimpStackTraceMode stack_trace_mode = GIMP_STACK_TRACE_QUERY;
static gchar *full_prog_name = NULL;
static gchar *backtrace_file = NULL;
static gchar *backup_path = NULL;
static guint log_domain_handler_ids[G_N_ELEMENTS (log_domains)];
static guint gegl_handler_id = 0;
static GimpLogHandler log_domain_handler = 0;
static guint global_handler_id = 0;
......@@ -122,8 +89,6 @@ errors_init (Gimp *gimp,
GimpStackTraceMode _stack_trace_mode,
const gchar *_backtrace_file)
{
gint i;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (_full_prog_name != NULL);
g_return_if_fail (full_prog_name == NULL);
......@@ -151,18 +116,12 @@ errors_init (Gimp *gimp,
backup_path = g_build_filename (gimp_directory (), "backups",
"backup-XXX.xcf", NULL);
for (i = 0; i < G_N_ELEMENTS (log_domains); i++)
log_domain_handler_ids[i] = g_log_set_handler (log_domains[i],
log_domain_handler = gimp_log_set_handler (FALSE,
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_CRITICAL,
gimp_message_log_func, gimp);
gegl_handler_id = g_log_set_handler ("GEGL",
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_CRITICAL,
gimp_message_log_func, gimp);
global_handler_id = g_log_set_handler (NULL,
G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
gimp_error_log_func, gimp);
......@@ -171,14 +130,20 @@ errors_init (Gimp *gimp,
void
errors_exit (void)
{
gint i;
if (log_domain_handler)
{
gimp_log_remove_handler (log_domain_handler);
for (i = 0; i < G_N_ELEMENTS (log_domains); i++)
g_log_remove_handler (log_domains[i], log_domain_handler_ids[i]);
log_domain_handler = 0;
}
g_log_remove_handler ("GEGL", gegl_handler_id);
if (global_handler_id)
{
g_log_remove_handler (NULL, global_handler_id);
global_handler_id = 0;
}
the_errors_gimp = NULL;
if (backtrace_file)
......
......@@ -48,6 +48,41 @@ static const GDebugKey log_keys[] =
{ "xcf", GIMP_LOG_XCF }
};
static const gchar * const log_domains[] =
{
"Gimp",
"Gimp-Actions",
"Gimp-Base",
"Gimp-Composite",
"Gimp-Config",
"Gimp-Core",
"Gimp-Dialogs",
"Gimp-Display",
"Gimp-File",
"Gimp-GEGL",
"Gimp-GUI",
"Gimp-Menus",
"Gimp-Operations",
"Gimp-PDB",
"Gimp-Paint",
"Gimp-Paint-Funcs",
"Gimp-Plug-In",
"Gimp-Text",
"Gimp-Tools",
"Gimp-Vectors",
"Gimp-Widgets",
"Gimp-XCF",
"LibGimpBase",
"LibGimpColor",
"LibGimpConfig",
"LibGimpMath",
"LibGimpModule",
"LibGimpThumb",
"LibGimpWidgets",
"GEGL",
NULL
};
GimpLogFlags gimp_log_flags = 0;
......@@ -139,3 +174,46 @@ gimp_logv (GimpLogFlags flags,
g_free (message);
}
GimpLogHandler
gimp_log_set_handler (gboolean global,
GLogLevelFlags log_levels,
GLogFunc log_func,
gpointer user_data)
{
GimpLogHandler handler;
gint n;
gint i;
g_return_val_if_fail (log_func != NULL, NULL);
n = G_N_ELEMENTS (log_domains) - (global ? 1 : 0);
handler = g_new (guint, n + 1);
handler[0] = n;
for (i = 0; i < n; i++)
{
handler[i + 1] = g_log_set_handler (log_domains[i], log_levels,
log_func, user_data);
}
return handler;
}
void
gimp_log_remove_handler (GimpLogHandler handler)
{
gint n;
gint i;
g_return_if_fail (handler != NULL);
n = handler[0];
for (i = 0; i < n; i++)
g_log_remove_handler (log_domains[i], handler[i + 1]);
g_free (handler);
}
......@@ -19,6 +19,9 @@
#define __GIMP_LOG_H__
typedef guint *GimpLogHandler;
typedef enum
{
GIMP_LOG_TOOL_EVENTS = 1 << 0,
......@@ -61,6 +64,12 @@ void gimp_logv (GimpLogFlags flags,
const gchar *format,
va_list args) G_GNUC_PRINTF (4, 0);
GimpLogHandler gimp_log_set_handler (gboolean global,
GLogLevelFlags log_levels,
GLogFunc log_func,
gpointer user_data);
void gimp_log_remove_handler (GimpLogHandler handler);
#ifdef G_HAVE_ISO_VARARGS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment