app: port gimp-log to also work with latest GLib
This commit is contained in:
@ -23,20 +23,7 @@
|
|||||||
#include "gimp-log.h"
|
#include "gimp-log.h"
|
||||||
|
|
||||||
|
|
||||||
GimpLogFlags gimp_log_flags = 0;
|
static const GDebugKey log_keys[] =
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
const GDebugKey log_keys[] =
|
|
||||||
{
|
{
|
||||||
{ "tool-events", GIMP_LOG_TOOL_EVENTS },
|
{ "tool-events", GIMP_LOG_TOOL_EVENTS },
|
||||||
{ "tool-focus", GIMP_LOG_TOOL_FOCUS },
|
{ "tool-focus", GIMP_LOG_TOOL_FOCUS },
|
||||||
@ -59,6 +46,23 @@ gimp_log_init (void)
|
|||||||
{ "brush-cache", GIMP_LOG_BRUSH_CACHE }
|
{ "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',
|
/* g_parse_debug_string() has special treatment of the string 'help',
|
||||||
* but we want to use it for the GIMP_LOG_HELP domain
|
* but we want to use it for the GIMP_LOG_HELP domain
|
||||||
*/
|
*/
|
||||||
@ -75,27 +79,36 @@ gimp_log_init (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gimp_log (const gchar *function,
|
gimp_log (GimpLogFlags flags,
|
||||||
|
const gchar *function,
|
||||||
gint line,
|
gint line,
|
||||||
const gchar *domain,
|
|
||||||
const gchar *format,
|
const gchar *format,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start (args, format);
|
va_start (args, format);
|
||||||
gimp_logv (function, line, domain, format, args);
|
gimp_logv (flags, function, line, format, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gimp_logv (const gchar *function,
|
gimp_logv (GimpLogFlags flags,
|
||||||
|
const gchar *function,
|
||||||
gint line,
|
gint line,
|
||||||
const gchar *domain,
|
|
||||||
const gchar *format,
|
const gchar *format,
|
||||||
va_list args)
|
va_list args)
|
||||||
{
|
{
|
||||||
|
const gchar *domain = "unknown";
|
||||||
gchar *message;
|
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)
|
if (format)
|
||||||
message = g_strdup_vprintf (format, args);
|
message = g_strdup_vprintf (format, args);
|
||||||
|
@ -47,14 +47,14 @@ extern GimpLogFlags gimp_log_flags;
|
|||||||
|
|
||||||
|
|
||||||
void gimp_log_init (void);
|
void gimp_log_init (void);
|
||||||
void gimp_log (const gchar *function,
|
void gimp_log (GimpLogFlags flags,
|
||||||
|
const gchar *function,
|
||||||
gint line,
|
gint line,
|
||||||
const gchar *domain,
|
|
||||||
const gchar *format,
|
const gchar *format,
|
||||||
...) G_GNUC_PRINTF (4, 5);
|
...) G_GNUC_PRINTF (4, 5);
|
||||||
void gimp_logv (const gchar *function,
|
void gimp_logv (GimpLogFlags flags,
|
||||||
|
const gchar *function,
|
||||||
gint line,
|
gint line,
|
||||||
const gchar *domain,
|
|
||||||
const gchar *format,
|
const gchar *format,
|
||||||
va_list args);
|
va_list args);
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ void gimp_logv (const gchar *function,
|
|||||||
#define GIMP_LOG(type, ...) \
|
#define GIMP_LOG(type, ...) \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
if (gimp_log_flags & GIMP_LOG_##type) \
|
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
|
} G_STMT_END
|
||||||
|
|
||||||
#elif defined(G_HAVE_GNUC_VARARGS)
|
#elif defined(G_HAVE_GNUC_VARARGS)
|
||||||
@ -72,7 +72,7 @@ void gimp_logv (const gchar *function,
|
|||||||
#define GIMP_LOG(type, format...) \
|
#define GIMP_LOG(type, format...) \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
if (gimp_log_flags & GIMP_LOG_##type) \
|
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
|
} G_STMT_END
|
||||||
|
|
||||||
#else /* no varargs macros */
|
#else /* no varargs macros */
|
||||||
@ -112,7 +112,7 @@ GIMP_LOG (GimpLogFlags flags,
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, format);
|
va_start (args, format);
|
||||||
if (gimp_log_flags & flags)
|
if (gimp_log_flags & flags)
|
||||||
gimp_logv ("", 0, "", format, args);
|
gimp_logv (type, "", 0, format, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user