ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00765
[Merge] lp:~ted/indicator-applet/log-to-file into lp:indicator-applet
Ted Gould has proposed merging lp:~ted/indicator-applet/log-to-file into lp:indicator-applet.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
Making it so the logs go out to a file in an async fashion. This should
get us some debug info as things come up.
--
https://code.launchpad.net/~ted/indicator-applet/log-to-file/+merge/17695
Your team ayatana-commits is subscribed to branch lp:indicator-applet.
=== modified file 'src/applet-main.c'
--- src/applet-main.c 2010-01-19 05:29:03 +0000
+++ src/applet-main.c 2010-01-19 22:31:11 +0000
@@ -20,6 +20,7 @@
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdlib.h>
#include <config.h>
#include <panel-applet.h>
@@ -73,6 +74,20 @@
#endif
/*************
+ * log files
+ * ***********/
+#ifdef INDICATOR_APPLET
+#define LOG_FILE_NAME "indicator-applet.log"
+#endif
+#ifdef INDICATOR_APPLET_SESSION
+#define LOG_FILE_NAME "indicator-applet-session.log"
+#endif
+#ifdef INDICATOR_APPLET_COMPLETE
+#define LOG_FILE_NAME "indicator-applet-complete.log"
+#endif
+GOutputStream * log_file = NULL;
+
+/*************
* init function
* ***********/
@@ -378,6 +393,58 @@
#endif
#define N_(x) x
+static void
+log_to_file_cb (GObject * source_obj, GAsyncResult * result, gpointer user_data)
+{
+ g_free(user_data);
+ return;
+}
+
+static void
+log_to_file (const gchar * domain, GLogLevelFlags level, const gchar * message, gpointer data)
+{
+ if (log_file == NULL) {
+ GError * error = NULL;
+ gchar * filename = g_build_path(g_get_user_cache_dir(), LOG_FILE_NAME, NULL);
+ GFile * file = g_file_new_for_path(filename);
+ g_free(filename);
+
+ if (!g_file_test(g_get_user_cache_dir(), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+ GFile * cachedir = g_file_new_for_path(g_get_user_cache_dir());
+ g_file_make_directory_with_parents(cachedir, NULL, &error);
+
+ if (error != NULL) {
+ g_error("Unable to make directory '%s' for log file: %s", g_get_user_cache_dir(), error->message);
+ return;
+ }
+ }
+
+ g_file_delete(file, NULL, NULL);
+
+ GFileIOStream * io = g_file_create_readwrite(file,
+ G_FILE_CREATE_REPLACE_DESTINATION, /* flags */
+ NULL, /* cancelable */
+ &error); /* error */
+ if (error != NULL) {
+ g_error("Unable to replace file: %s", error->message);
+ return;
+ }
+
+ log_file = g_io_stream_get_output_stream(G_IO_STREAM(io));
+ }
+
+ gchar * outputstring = g_strdup_printf("%s\n", message);
+ g_output_stream_write_async(log_file,
+ outputstring, /* data */
+ strlen(outputstring), /* length */
+ G_PRIORITY_LOW, /* priority */
+ NULL, /* cancelable */
+ log_to_file_cb, /* callback */
+ outputstring); /* data */
+
+ return;
+}
+
static gboolean
applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data)
{
@@ -415,6 +482,8 @@
#ifdef INDICATOR_APPLET_COMPLETE
g_set_application_name(_("Indicator Applet Complete"));
#endif
+
+ g_log_set_default_handler(log_to_file, NULL);
}
/* Set panel options */
Follow ups