Skip to content

Commit

Permalink
Fix verbose/debug logging, add G_LOG_DOMAIN for easier tracking
Browse files Browse the repository at this point in the history
in journalctl.

Verbose mode was broken for gtk-based daemons, as post-gtk_init
is too late to set G_MESSAGES_DEBUG.
  • Loading branch information
mtwebster committed Nov 7, 2024
1 parent a690627 commit f09f592
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugins/a11y-settings/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: a11y_settings_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/automount/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: automount_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install_rpath: join_paths(prefix, apilibdir),
Expand Down
1 change: 1 addition & 0 deletions plugins/background/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: background_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/clipboard/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: clipboard_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/color/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ executable(
dependencies: color_deps,
c_args: [
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DBINDIR="@0@"'.format(bindir),
],
install: true,
Expand Down
15 changes: 14 additions & 1 deletion plugins/common/daemon-skeleton-gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ handle_signal (gpointer user_data)
return G_SOURCE_REMOVE;
}

static void
message_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
/* Make this look like normal console output */
if (log_level & G_LOG_LEVEL_DEBUG)
printf ("csd-%s: %s\n", PLUGIN_NAME, message);
else
printf ("%s: %s\n", g_get_prgname (), message);
}

int
main (int argc, char **argv)
{
Expand Down Expand Up @@ -221,7 +234,7 @@ main (int argc, char **argv)
g_unix_signal_add (SIGTERM, (GSourceFunc) handle_signal, NULL);

if (verbose)
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL);

if (timeout > 0) {
guint id;
Expand Down
19 changes: 15 additions & 4 deletions plugins/common/daemon-skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ handle_signal (gpointer user_data)
return G_SOURCE_REMOVE;
}

static void
message_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
/* Make this look like normal console output */
if (log_level & G_LOG_LEVEL_DEBUG)
printf ("csd-%s: %s\n", PLUGIN_NAME, message);
else
printf ("%s: %s\n", g_get_prgname (), message);
}

int
main (int argc, char **argv)
{
Expand Down Expand Up @@ -208,10 +221,8 @@ main (int argc, char **argv)

g_unix_signal_add (SIGTERM, (GSourceFunc) handle_signal, loop);

if (verbose) {
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
setlinebuf (stdout);
}
if (verbose)
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL);

if (timeout > 0) {
guint id;
Expand Down
1 change: 1 addition & 0 deletions plugins/datetime/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if polkit.found()
include_directories: [include_dirs, common_inc],
dependencies: datetime_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/housekeeping/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: housekeeping_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/keyboard/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ executable(
include_directories: [include_dirs, common_inc, include_enums],
dependencies: keyboard_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
'-DDATADIR="@0@"'.format(datadir),
],
Expand Down
1 change: 1 addition & 0 deletions plugins/media-keys/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ executable(
include_directories: [include_dirs, common_inc, include_enums],
dependencies: media_keys_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/power/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ executable(
dependencies: power_deps,
c_args: [
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
],
install_rpath: join_paths(prefix, apilibdir),
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/print-notifications/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: print_notifications_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/screensaver-proxy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: screensaver_proxy_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/settings-remap/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: settings_remap_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/smartcard/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ executable(
include_directories: [include_dirs, common_inc],
dependencies: smartcard_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
],
install: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/wacom/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ deps = [
]

cflags = [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
]

Expand Down
1 change: 1 addition & 0 deletions plugins/xsettings/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ executable(
include_directories: [include_dirs, common_inc, include_enums],
dependencies: xsettings_deps,
c_args: [
'-DG_LOG_DOMAIN="csd-@0@"'.format(plugin_name),
'-DPLUGIN_NAME="@0@"'.format(plugin_name),
'-DGTK_MODULES_DIRECTORY="@0@/@1@/cinnamon-settings-daemon-@2@/gtk-modules/"'.format(prefix, libdir, api_version),
],
Expand Down

0 comments on commit f09f592

Please sign in to comment.