app: port gimp-log to also work with latest GLib

This commit is contained in:
Michael Natterer 2011-11-09 23:32:41 +01:00
parent e5f6a6d9ea
commit 245c22f767
2 changed files with 59 additions and 46 deletions

View File

@ -23,21 +23,8 @@
#include "gimp-log.h"
GimpLogFlags gimp_log_flags = 0;
void
gimp_log_init (void)
static const GDebugKey log_keys[] =
{
const gchar *env_log_val = g_getenv ("GIMP_LOG");
if (! env_log_val)
env_log_val = g_getenv ("GIMP_DEBUG");
if (env_log_val)
{
const GDebugKey log_keys[] =
{
{ "tool-events", GIMP_LOG_TOOL_EVENTS },
{ "tool-focus", GIMP_LOG_TOOL_FOCUS },
{ "dnd", GIMP_LOG_DND },
@ -57,8 +44,25 @@ gimp_log_init (void)
{ "instances", GIMP_LOG_INSTANCES },
{ "rectangle-tool", GIMP_LOG_RECTANGLE_TOOL },
{ "brush-cache", GIMP_LOG_BRUSH_CACHE }
};
};
GimpLogFlags gimp_log_flags = 0;
void
gimp_log_init (void)
{
const gchar *env_log_val = g_getenv ("GIMP_LOG");
if (! env_log_val)
env_log_val = g_getenv ("GIMP_DEBUG");
if (env_log_val)
g_setenv ("G_MESSAGES_DEBUG", env_log_val, TRUE);
if (env_log_val)
{
/* g_parse_debug_string() has special treatment of the string 'help',
* but we want to use it for the GIMP_LOG_HELP domain
*/
@ -75,27 +79,36 @@ gimp_log_init (void)
}
void
gimp_log (const gchar *function,
gimp_log (GimpLogFlags flags,
const gchar *function,
gint line,
const gchar *domain,
const gchar *format,
...)
{
va_list args;
va_start (args, format);
gimp_logv (function, line, domain, format, args);
gimp_logv (flags, function, line, format, args);
va_end (args);
}
void
gimp_logv (const gchar *function,
gimp_logv (GimpLogFlags flags,
const gchar *function,
gint line,
const gchar *domain,
const gchar *format,
va_list args)
{
const gchar *domain = "unknown";
gchar *message;
gint i;
for (i = 0; i < G_N_ELEMENTS (log_keys); i++)
if (log_keys[i].value == flags)
{
domain = log_keys[i].key;
break;
}
if (format)
message = g_strdup_vprintf (format, args);

View File

@ -47,14 +47,14 @@ extern GimpLogFlags gimp_log_flags;
void gimp_log_init (void);
void gimp_log (const gchar *function,
void gimp_log (GimpLogFlags flags,
const gchar *function,
gint line,
const gchar *domain,
const gchar *format,
...) G_GNUC_PRINTF (4, 5);
void gimp_logv (const gchar *function,
void gimp_logv (GimpLogFlags flags,
const gchar *function,
gint line,
const gchar *domain,
const gchar *format,
va_list args);
@ -64,7 +64,7 @@ void gimp_logv (const gchar *function,
#define GIMP_LOG(type, ...) \
G_STMT_START { \
if (gimp_log_flags & GIMP_LOG_##type) \
gimp_log (G_STRFUNC, __LINE__, #type, __VA_ARGS__); \
gimp_log (GIMP_LOG_##type, G_STRFUNC, __LINE__, __VA_ARGS__); \
} G_STMT_END
#elif defined(G_HAVE_GNUC_VARARGS)
@ -72,7 +72,7 @@ void gimp_logv (const gchar *function,
#define GIMP_LOG(type, format...) \
G_STMT_START { \
if (gimp_log_flags & GIMP_LOG_##type) \
gimp_log (G_STRFUNC, __LINE__, #type, format); \
gimp_log (GIMP_LOG_##type, G_STRFUNC, __LINE__, format); \
} G_STMT_END
#else /* no varargs macros */
@ -112,7 +112,7 @@ GIMP_LOG (GimpLogFlags flags,
va_list args;
va_start (args, format);
if (gimp_log_flags & flags)
gimp_logv ("", 0, "", format, args);
gimp_logv (type, "", 0, format, args);
va_end (args);
}