|
19 | 19 | #define GNOME_DESKTOP_USE_UNSTABLE_API |
20 | 20 | #include <libcinnamon-desktop/gnome-systemd.h> |
21 | 21 |
|
| 22 | +// Warnings generated by C libraries (clutter, muffin, glib, etc...) can be |
| 23 | +// difficult to trace when they originate at the javascript level. |
| 24 | +// |
| 25 | +// Enabling (1) will print the current js call stack after the warning is logged. |
| 26 | +// Note, this may result in the stack being printed twice in some instances, as we |
| 27 | +// already do this for specific warnings elsewhere. It may be nicer to get rid of |
| 28 | +// those others (in cjs and st-widget I think) and permanently enable the logging |
| 29 | +// here. |
| 30 | +#define PRINT_JS_STACK_FOR_C_WARNINGS 0 |
| 31 | + |
22 | 32 | static CinnamonGlobal *the_object = NULL; |
23 | 33 |
|
24 | 34 | enum { |
@@ -60,6 +70,8 @@ G_DEFINE_TYPE(CinnamonGlobal, cinnamon_global, G_TYPE_OBJECT); |
60 | 70 |
|
61 | 71 | static guint cinnamon_global_signals [LAST_SIGNAL] = { 0 }; |
62 | 72 |
|
| 73 | +static void setup_log_handler (CinnamonGlobal *global); |
| 74 | + |
63 | 75 | static void |
64 | 76 | cinnamon_global_set_property(GObject *object, |
65 | 77 | guint prop_id, |
@@ -234,6 +246,8 @@ cinnamon_global_init (CinnamonGlobal *global) |
234 | 246 |
|
235 | 247 | global->settings = g_settings_new ("org.cinnamon"); |
236 | 248 |
|
| 249 | + setup_log_handler (global); |
| 250 | + |
237 | 251 | setup_notifications_service (global); |
238 | 252 |
|
239 | 253 | global->ui_scale = 1; |
@@ -908,6 +922,28 @@ _cinnamon_global_get_gjs_context (CinnamonGlobal *global) |
908 | 922 | return global->js_context; |
909 | 923 | } |
910 | 924 |
|
| 925 | +static void |
| 926 | +log_handler (const char *domain, |
| 927 | + GLogLevelFlags level, |
| 928 | + const char *message, |
| 929 | + gpointer data) |
| 930 | +{ |
| 931 | + g_log_default_handler (domain, level, message, data); |
| 932 | + |
| 933 | + if ((level & (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)) != 0) { |
| 934 | + gjs_dumpstack (); |
| 935 | + } |
| 936 | +} |
| 937 | + |
| 938 | +static void |
| 939 | +setup_log_handler (CinnamonGlobal *global) |
| 940 | +{ |
| 941 | + if (!PRINT_JS_STACK_FOR_C_WARNINGS) |
| 942 | + return; |
| 943 | + |
| 944 | + g_log_set_default_handler (log_handler, NULL); |
| 945 | +} |
| 946 | + |
911 | 947 | static guint32 |
912 | 948 | get_current_time_maybe_roundtrip (CinnamonGlobal *global) |
913 | 949 | { |
|
0 commit comments