Merge lp:~ted/indicator-applet/log-to-file into lp:indicator-applet/0.4

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/indicator-applet/log-to-file
Merge into: lp:indicator-applet/0.4
Diff against target: 100 lines (+69/-0)
1 file modified
src/applet-main.c (+69/-0)
To merge this branch: bzr merge lp:~ted/indicator-applet/log-to-file
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+17695@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

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.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Log files are for wimps. Real men guess what errors happened.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
20with this program. If not, see <http://www.gnu.org/licenses/>.20with this program. If not, see <http://www.gnu.org/licenses/>.
21*/21*/
2222
23#include <stdlib.h>
23#include <config.h>24#include <config.h>
24#include <panel-applet.h>25#include <panel-applet.h>
2526
@@ -73,6 +74,20 @@
73#endif74#endif
7475
75/*************76/*************
77 * log files
78 * ***********/
79#ifdef INDICATOR_APPLET
80#define LOG_FILE_NAME "indicator-applet.log"
81#endif
82#ifdef INDICATOR_APPLET_SESSION
83#define LOG_FILE_NAME "indicator-applet-session.log"
84#endif
85#ifdef INDICATOR_APPLET_COMPLETE
86#define LOG_FILE_NAME "indicator-applet-complete.log"
87#endif
88GOutputStream * log_file = NULL;
89
90/*************
76 * init function91 * init function
77 * ***********/92 * ***********/
7893
@@ -378,6 +393,58 @@
378#endif393#endif
379#define N_(x) x394#define N_(x) x
380395
396static void
397log_to_file_cb (GObject * source_obj, GAsyncResult * result, gpointer user_data)
398{
399 g_free(user_data);
400 return;
401}
402
403static void
404log_to_file (const gchar * domain, GLogLevelFlags level, const gchar * message, gpointer data)
405{
406 if (log_file == NULL) {
407 GError * error = NULL;
408 gchar * filename = g_build_path(g_get_user_cache_dir(), LOG_FILE_NAME, NULL);
409 GFile * file = g_file_new_for_path(filename);
410 g_free(filename);
411
412 if (!g_file_test(g_get_user_cache_dir(), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
413 GFile * cachedir = g_file_new_for_path(g_get_user_cache_dir());
414 g_file_make_directory_with_parents(cachedir, NULL, &error);
415
416 if (error != NULL) {
417 g_error("Unable to make directory '%s' for log file: %s", g_get_user_cache_dir(), error->message);
418 return;
419 }
420 }
421
422 g_file_delete(file, NULL, NULL);
423
424 GFileIOStream * io = g_file_create_readwrite(file,
425 G_FILE_CREATE_REPLACE_DESTINATION, /* flags */
426 NULL, /* cancelable */
427 &error); /* error */
428 if (error != NULL) {
429 g_error("Unable to replace file: %s", error->message);
430 return;
431 }
432
433 log_file = g_io_stream_get_output_stream(G_IO_STREAM(io));
434 }
435
436 gchar * outputstring = g_strdup_printf("%s\n", message);
437 g_output_stream_write_async(log_file,
438 outputstring, /* data */
439 strlen(outputstring), /* length */
440 G_PRIORITY_LOW, /* priority */
441 NULL, /* cancelable */
442 log_to_file_cb, /* callback */
443 outputstring); /* data */
444
445 return;
446}
447
381static gboolean448static gboolean
382applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data)449applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data)
383{450{
@@ -415,6 +482,8 @@
415#ifdef INDICATOR_APPLET_COMPLETE482#ifdef INDICATOR_APPLET_COMPLETE
416 g_set_application_name(_("Indicator Applet Complete"));483 g_set_application_name(_("Indicator Applet Complete"));
417#endif484#endif
485
486 g_log_set_default_handler(log_to_file, NULL);
418 }487 }
419488
420 /* Set panel options */489 /* Set panel options */

Subscribers

People subscribed via source and target branches

to status/vote changes: