[Xfce4-commits] <xfce4-indicator-plugin:master> Added a log handler
Andrzej
noreply at xfce.org
Sat Aug 31 04:12:02 CEST 2013
Updating branch refs/heads/master
to 0d48094558b03f3d5c66708b0a919db996985f8f (commit)
from 4eccf5405f8c7101c071110c54a108cdab9b3a48 (commit)
commit 0d48094558b03f3d5c66708b0a919db996985f8f
Author: Andrzej <ndrwrdck at gmail.com>
Date: Sat Aug 31 00:52:17 2013 +0100
Added a log handler
panel-plugin/indicator.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index 26d0ebb..0e7b996 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -82,6 +82,9 @@ struct _IndicatorPlugin
/* indicator settings */
IndicatorConfig *config;
+
+ /* log file */
+ FILE *logfile;
};
@@ -119,6 +122,11 @@ indicator_init (IndicatorPlugin *indicator)
plugin but not internal one (loaded by "xfce4-panel" itself).
The following lines makes only g_error critical. */
g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
+
+ indicator->item = NULL;
+ indicator->buttonbox = NULL;
+ indicator->config = NULL;
+ indicator->logfile = NULL;
}
@@ -225,6 +233,49 @@ indicator_size_changed (XfcePanelPlugin *plugin,
}
+
+static void
+indicator_log_handler (const gchar *domain,
+ GLogLevelFlags level,
+ const gchar *message,
+ gpointer data)
+{
+ IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (data);
+ gchar *path;
+ const gchar *prefix;
+
+ if (indicator->logfile == NULL)
+ {
+ g_mkdir_with_parents (g_get_user_cache_dir (), 0755);
+ path = g_build_filename (g_get_user_cache_dir (), "xfce4-indicator-plugin.log", NULL);
+ indicator->logfile = fopen (path, "w");
+ g_free (path);
+ }
+
+ if (indicator->logfile)
+ {
+ switch (level & G_LOG_LEVEL_MASK)
+ {
+ case G_LOG_LEVEL_ERROR: prefix = "ERROR"; break;
+ case G_LOG_LEVEL_CRITICAL: prefix = "CRITICAL"; break;
+ case G_LOG_LEVEL_WARNING: prefix = "WARNING"; break;
+ case G_LOG_LEVEL_MESSAGE: prefix = "MESSAGE"; break;
+ case G_LOG_LEVEL_INFO: prefix = "INFO"; break;
+ case G_LOG_LEVEL_DEBUG: prefix = "DEBUG"; break;
+ default: prefix = "LOG"; break;
+ }
+
+ fprintf (indicator->logfile, "%-10s %-25s %s\n", prefix, domain, message);
+ fflush (indicator->logfile);
+ }
+
+ /* print log to the stdout */
+ if (level & G_LOG_LEVEL_ERROR || level & G_LOG_LEVEL_CRITICAL)
+ g_log_default_handler (domain, level, message, NULL);
+}
+
+
+
static void
indicator_construct (XfcePanelPlugin *plugin)
{
@@ -238,6 +289,9 @@ indicator_construct (XfcePanelPlugin *plugin)
/* setup transation domain */
xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+ /* log messages to a file */
+ g_log_set_default_handler(indicator_log_handler, plugin);
+
/* Init some theme/icon stuff */
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
INDICATOR_ICONS_DIR);
More information about the Xfce4-commits
mailing list