Mercurial > projects > xwrited
comparison xwrited-debug.c @ 1:0907cc7064d4
Add support for newer glib versions
Do not call g_type_init() in glib >= 2.35 where it has been deprecated.
glib >= 2.32 only shows debug messages if the G_MESSAGES_DEBUG environment
variable contains the log domain or "all", so add the log domain to
G_MESSAGES_DEBUG if necessary if the "-d" commandline option was specified.
author | Guido Berhoerster <guido+xwrited@berhoerster.name> |
---|---|
date | Sun, 27 Apr 2014 23:12:06 +0200 |
parents | 52694b49dcc4 |
children | 4a5330979433 |
comparison
equal
deleted
inserted
replaced
0:52694b49dcc4 | 1:0907cc7064d4 |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name> | 2 * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name> |
3 * | 3 * |
4 * Permission is hereby granted, free of charge, to any person obtaining | 4 * Permission is hereby granted, free of charge, to any person obtaining |
5 * a copy of this software and associated documentation files (the | 5 * a copy of this software and associated documentation files (the |
6 * "Software"), to deal in the Software without restriction, including | 6 * "Software"), to deal in the Software without restriction, including |
7 * without limitation the rights to use, copy, modify, merge, publish, | 7 * without limitation the rights to use, copy, modify, merge, publish, |
27 #include <stdarg.h> | 27 #include <stdarg.h> |
28 #include <glib.h> | 28 #include <glib.h> |
29 | 29 |
30 #include "xwrited-debug.h" | 30 #include "xwrited-debug.h" |
31 | 31 |
32 #if !GLIB_CHECK_VERSION(2, 32, 0) | |
32 static void | 33 static void |
33 dummy_log_handler(const gchar *log_domain, GLogLevelFlags log_level, | 34 dummy_log_handler(const gchar *log_domain, GLogLevelFlags log_level, |
34 const gchar *message, gpointer data) | 35 const gchar *message, gpointer data) |
35 { | 36 { |
36 /* drop all messages */ | 37 /* drop all messages */ |
37 } | 38 } |
39 #endif /* !GLIB_CHECK_VERSION (2,32,0) */ | |
38 | 40 |
39 void | 41 void |
40 xwrited_debug_init(gboolean debug_mode) | 42 xwrited_debug_init(gboolean debug_mode) |
41 { | 43 { |
44 /* | |
45 * glib >= 2.32 only shows debug messages if the G_MESSAGES_DEBUG | |
46 * environment variable contains the log domain or "all", earlier glib | |
47 * version always show debugging output | |
48 */ | |
49 #if GLIB_CHECK_VERSION(2, 32, 0) | |
50 const gchar *debug_env; | |
51 gchar *debug_env_new; | |
52 | |
53 if (debug_mode) { | |
54 debug_env = g_getenv("G_MESSAGES_DEBUG"); | |
55 | |
56 if (debug_env == NULL) { | |
57 g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE); | |
58 } else if (strstr(debug_env, G_LOG_DOMAIN) == NULL) { | |
59 debug_env_new = g_strdup_printf("%s %s", debug_env, | |
60 G_LOG_DOMAIN); | |
61 g_setenv("G_MESSAGES_DEBUG", debug_env_new, TRUE); | |
62 g_free(debug_env_new); | |
63 } | |
64 } | |
65 #else | |
42 if (!debug_mode) { | 66 if (!debug_mode) { |
43 g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, | 67 g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, |
44 dummy_log_handler, NULL); | 68 dummy_log_handler, NULL); |
45 } | 69 } |
70 #endif /* GLIB_CHECK_VERSION (2,32,0) */ | |
46 } | 71 } |