From 3229e67f643c3024f0faf438206024814cc91244 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 15 Nov 2007 10:57:53 +0000 Subject: [PATCH] app/Makefile.am new files implementing a log facility which can be enabled 2007-11-15 Michael Natterer * app/Makefile.am * app/gimp-log.[ch]: new files implementing a log facility which can be enabled using the GIMP_LOG environment variable. * app/main.c: initialize it. * app/display/gimpdisplayshell-callbacks.c: use it instead of private debugging macros that need to be enabled at compile time. svn path=/trunk/; revision=24160 --- ChangeLog | 13 ++++- app/Makefile.am | 2 + app/display/gimpdisplayshell-callbacks.c | 34 +++++-------- app/gimp-log.c | 65 ++++++++++++++++++++++++ app/gimp-log.h | 47 +++++++++++++++++ app/main.c | 3 ++ 6 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 app/gimp-log.c create mode 100644 app/gimp-log.h diff --git a/ChangeLog b/ChangeLog index 77ecdcce89..5cdb8f4e24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-11-15 Michael Natterer + + * app/Makefile.am + * app/gimp-log.[ch]: new files implementing a log facility which + can be enabled using the GIMP_LOG environment variable. + + * app/main.c: initialize it. + + * app/display/gimpdisplayshell-callbacks.c: use it instead of + private debugging macros that need to be enabled at compile time. + 2007-11-15 Michael Natterer * app/core/gimpviewable.[ch]: add read-only property "frozen" and @@ -12,7 +23,7 @@ * app/tools/gimpcurvestool.c: set the background histogram instead. * app/widgets/gimphistogrameditor.[ch]: connect to "notify::frozen" - of the drawable and show its histogram at thje freezing point in + of the drawable and show its histogram at the freezing point in the background. This way the original histogram is visible while we are doing color corrections. diff --git a/app/Makefile.am b/app/Makefile.am index d9cbc4793c..2ab2c17957 100644 --- a/app/Makefile.am +++ b/app/Makefile.am @@ -50,6 +50,8 @@ app_sources = \ sanity.h \ units.c \ units.h \ + gimp-log.c \ + gimp-log.h \ gimp-intl.h gimp_2_5_SOURCES = $(app_sources) diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c index dd5b92f19e..874b1df983 100644 --- a/app/display/gimpdisplayshell-callbacks.c +++ b/app/display/gimpdisplayshell-callbacks.c @@ -76,18 +76,10 @@ #include "gimpdisplayshell-transform.h" #include "gimpnavigationeditor.h" +#include "gimp-log.h" #include "gimp-intl.h" -/* #define DEBUG_TOOL_EVENTS */ - -#ifdef DEBUG_TOOL_EVENTS -#define D(stmnt) stmnt -#else -#define D(stmnt) -#endif - - /* local function prototypes */ static void gimp_display_shell_vscrollbar_update (GtkAdjustment *adjustment, @@ -676,7 +668,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, { GdkEventCrossing *cevent = (GdkEventCrossing *) event; - D (g_printerr ("tool event (display %p): ENTER_NOTIFY\n", display)); + GIMP_LOG (TOOLS, "event (display %p): ENTER_NOTIFY", display); if (cevent->mode != GDK_CROSSING_NORMAL) return TRUE; @@ -694,7 +686,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, { GdkEventCrossing *cevent = (GdkEventCrossing *) event; - D (g_printerr ("tool event (display %p): LEAVE_NOTIFY\n", display)); + GIMP_LOG (TOOLS, "event (display %p): LEAVE_NOTIFY", display); if (cevent->mode != GDK_CROSSING_NORMAL) return TRUE; @@ -710,7 +702,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, break; case GDK_PROXIMITY_IN: - D (g_printerr ("tool event (display %p): PROXIMITY_IN\n", display)); + GIMP_LOG (TOOLS, "event (display %p): PROXIMITY_IN", display); tool_manager_oper_update_active (gimp, &image_coords, state, @@ -719,7 +711,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, break; case GDK_PROXIMITY_OUT: - D (g_printerr ("tool event (display %p): PROXIMITY_OUT\n", display)); + GIMP_LOG (TOOLS, "event (display %p): PROXIMITY_OUT", display); shell->proximity = FALSE; gimp_display_shell_clear_cursor (shell); @@ -736,7 +728,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, if (fevent->in) { - D (g_printerr ("tool event (display %p): FOCUS_IN\n", display)); + GIMP_LOG (TOOLS, "event (display %p): FOCUS_IN", display); GTK_WIDGET_SET_FLAGS (canvas, GTK_HAS_FOCUS); @@ -752,7 +744,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, } else { - D (g_printerr ("tool event (display %p): FOCUS_OUT\n", display)); + GIMP_LOG (TOOLS, "event (display %p): FOCUS_OUT", display); GTK_WIDGET_UNSET_FLAGS (canvas, GTK_HAS_FOCUS); @@ -782,7 +774,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, GdkEventButton *bevent = (GdkEventButton *) event; GdkEventMask event_mask; - D (g_printerr ("tool event (display %p): BUTTON_PRESS\n", display)); + GIMP_LOG (TOOLS, "event (display %p): BUTTON_PRESS", display); if (! GTK_WIDGET_HAS_FOCUS (canvas)) { @@ -928,7 +920,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, { GdkEventButton *bevent = (GdkEventButton *) event; - D (g_printerr ("tool event (display %p): BUTTON_RELEASE\n", display)); + GIMP_LOG (TOOLS, "event (display %p): BUTTON_RELEASE", display); gimp_display_shell_autoscroll_stop (shell); @@ -994,7 +986,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, GdkScrollDirection direction; GimpController *wheel; - D (g_printerr ("tool event (display %p): SCROLL\n", display)); + GIMP_LOG (TOOLS, "event (display %p): SCROLL", display); wheel = gimp_controllers_get_wheel (gimp); @@ -1097,7 +1089,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, GdkEventMotion *mevent = (GdkEventMotion *) event; GdkEvent *compressed_motion = NULL; - D (g_printerr ("tool event (display %p): MOTION_NOTIFY\n", display)); + GIMP_LOG (TOOLS, "event (display %p): MOTION_NOTIFY", display); if (gimp->busy) return TRUE; @@ -1258,7 +1250,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, break; case GDK_KEY_PRESS: - D (g_printerr ("tool event (display %p): KEY_PRESS\n", display)); + GIMP_LOG (TOOLS, "event (display %p): KEY_PRESS", display); if (state & GDK_BUTTON1_MASK) { @@ -1370,7 +1362,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas, break; case GDK_KEY_RELEASE: - D (g_printerr ("tool event (display %p): KEY_RELEASE\n", display)); + GIMP_LOG (TOOLS, "event (display %p): KEY_RELEASE", display); if (state & GDK_BUTTON1_MASK) { diff --git a/app/gimp-log.c b/app/gimp-log.c new file mode 100644 index 0000000000..c5d92f810a --- /dev/null +++ b/app/gimp-log.c @@ -0,0 +1,65 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "glib-object.h" + +#include "gimp-log.h" + + +GimpLogFlags gimp_log_flags = 0; + + +void +gimp_log_init (void) +{ + const gchar *env_log_val = g_getenv ("GIMP_LOG"); + + if (env_log_val) + { + const GDebugKey log_keys[] = + { + { "tools", GIMP_LOG_TOOLS } + }; + + gimp_log_flags = g_parse_debug_string (env_log_val, + log_keys, + G_N_ELEMENTS (log_keys)); + } +} + +void +gimp_log (const gchar *function, + gint line, + const gchar *domain, + const gchar *format, + ...) +{ + va_list args; + gchar *message; + + va_start (args, format); + message = g_strdup_vprintf (format, args); + va_end (args); + + g_log (domain, G_LOG_LEVEL_DEBUG, + "%s(%d): %s", function, line, message); + + g_free (message); +} diff --git a/app/gimp-log.h b/app/gimp-log.h new file mode 100644 index 0000000000..0a3ffeaed6 --- /dev/null +++ b/app/gimp-log.h @@ -0,0 +1,47 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_LOG_H__ +#define __GIMP_LOG_H__ + + +typedef enum +{ + GIMP_LOG_TOOLS = 1 << 0 +} GimpLogFlags; + + +#define GIMP_LOG(type, format...) \ + G_STMT_START { \ + if (gimp_log_flags && GIMP_LOG_##type) \ + gimp_log (G_STRFUNC, __LINE__, #type, format); \ + } G_STMT_END + + +extern GimpLogFlags gimp_log_flags; + + +void gimp_log_init (void); +void gimp_log (const gchar *function, + gint line, + const gchar *domain, + const gchar *format, + ...) G_GNUC_PRINTF (4, 5); + + +#endif /* __GIMP_LOG_H__ */ diff --git a/app/main.c b/app/main.c index d51d576305..60ea18c6cb 100644 --- a/app/main.c +++ b/app/main.c @@ -74,6 +74,7 @@ #include #endif +#include "gimp-log.h" #include "gimp-intl.h" @@ -299,6 +300,8 @@ main (int argc, gimp_env_init (FALSE); + gimp_log_init (); + gimp_init_i18n (); g_set_application_name (GIMP_NAME); -- GitLab