Commit a143bfdf 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.
parent 892fbafd
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "pdb/gimppdb.h" #include "pdb/gimppdb.h"
#include "errors.h" #include "errors.h"
#include "gimp-log.h"
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
#include <windows.h> #include <windows.h>
...@@ -53,49 +54,15 @@ ...@@ -53,49 +54,15 @@
/* private variables */ /* private variables */
static const gchar * const log_domains[] = static Gimp *the_errors_gimp = NULL;
{ static gboolean use_debug_handler = FALSE;
"Gimp", static GimpStackTraceMode stack_trace_mode = GIMP_STACK_TRACE_QUERY;
"Gimp-Actions", static gchar *full_prog_name = NULL;
"Gimp-Base", static gchar *backtrace_file = NULL;
"Gimp-Composite", static gchar *backup_path = NULL;
"Gimp-Config", static GFile *backup_file = NULL;
"Gimp-Core", static GimpLogHandler log_domain_handler = 0;
"Gimp-Dialogs", static guint global_handler_id = 0;
"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 GFile *backup_file = NULL;
static guint log_domain_handler_ids[G_N_ELEMENTS (log_domains)];
static guint gegl_handler_id = 0;
static guint global_handler_id = 0;
/* local function prototypes */ /* local function prototypes */
...@@ -123,8 +90,6 @@ errors_init (Gimp *gimp, ...@@ -123,8 +90,6 @@ errors_init (Gimp *gimp,
GimpStackTraceMode _stack_trace_mode, GimpStackTraceMode _stack_trace_mode,
const gchar *_backtrace_file) const gchar *_backtrace_file)
{ {
gint i;
g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (_full_prog_name != NULL); g_return_if_fail (_full_prog_name != NULL);
g_return_if_fail (full_prog_name == NULL); g_return_if_fail (full_prog_name == NULL);
...@@ -154,18 +119,12 @@ errors_init (Gimp *gimp, ...@@ -154,18 +119,12 @@ errors_init (Gimp *gimp,
backup_file = g_file_new_for_path (backup_path); backup_file = g_file_new_for_path (backup_path);
for (i = 0; i < G_N_ELEMENTS (log_domains); i++) log_domain_handler = gimp_log_set_handler (FALSE,
log_domain_handler_ids[i] = g_log_set_handler (log_domains[i], G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_CRITICAL,
G_LOG_LEVEL_CRITICAL, gimp_message_log_func, gimp);
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, global_handler_id = g_log_set_handler (NULL,
G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL, G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
gimp_error_log_func, gimp); gimp_error_log_func, gimp);
...@@ -174,13 +133,19 @@ errors_init (Gimp *gimp, ...@@ -174,13 +133,19 @@ errors_init (Gimp *gimp,
void void
errors_exit (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++) log_domain_handler = 0;
g_log_remove_handler (log_domains[i], log_domain_handler_ids[i]); }
if (global_handler_id)
{
g_log_remove_handler (NULL, global_handler_id);
g_log_remove_handler ("GEGL", gegl_handler_id); global_handler_id = 0;
g_log_remove_handler (NULL, global_handler_id); }
the_errors_gimp = NULL; the_errors_gimp = NULL;
......
...@@ -48,6 +48,41 @@ static const GDebugKey log_keys[] = ...@@ -48,6 +48,41 @@ static const GDebugKey log_keys[] =
{ "xcf", GIMP_LOG_XCF } { "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; GimpLogFlags gimp_log_flags = 0;
...@@ -139,3 +174,46 @@ gimp_logv (GimpLogFlags flags, ...@@ -139,3 +174,46 @@ gimp_logv (GimpLogFlags flags,
g_free (message); 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 @@ ...@@ -19,6 +19,9 @@
#define __GIMP_LOG_H__ #define __GIMP_LOG_H__
typedef guint *GimpLogHandler;
typedef enum typedef enum
{ {
GIMP_LOG_TOOL_EVENTS = 1 << 0, GIMP_LOG_TOOL_EVENTS = 1 << 0,
...@@ -49,17 +52,23 @@ typedef enum ...@@ -49,17 +52,23 @@ typedef enum
extern GimpLogFlags gimp_log_flags; extern GimpLogFlags gimp_log_flags;
void gimp_log_init (void); void gimp_log_init (void);
void gimp_log (GimpLogFlags flags, void gimp_log (GimpLogFlags flags,
const gchar *function, const gchar *function,
gint line, gint line,
const gchar *format, const gchar *format,
...) G_GNUC_PRINTF (4, 5); ...) G_GNUC_PRINTF (4, 5);
void gimp_logv (GimpLogFlags flags, void gimp_logv (GimpLogFlags flags,
const gchar *function, const gchar *function,
gint line, gint line,
const gchar *format, const gchar *format,
va_list args) G_GNUC_PRINTF (4, 0); 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 #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