[tracker] libtracker-common: Build log filename automatically from binary name



commit 07f24dfc548a2db1dc245921c4d5f452d6074d99
Author: Martyn Russell <martyn imendio com>
Date:   Sat Jul 11 00:06:59 2009 +0100

    libtracker-common: Build log filename automatically from binary name

 src/libtracker-common/tracker-log.c |   20 +++++++++++++++++---
 src/libtracker-common/tracker-log.h |    4 ++--
 src/tracker-extract/tracker-main.c  |   14 ++++----------
 src/tracker-miner-fs/tracker-main.c |   17 +++++------------
 src/tracker-store/tracker-main.c    |   10 ++--------
 5 files changed, 30 insertions(+), 35 deletions(-)
---
diff --git a/src/libtracker-common/tracker-log.c b/src/libtracker-common/tracker-log.c
index e96af23..494b19f 100644
--- a/src/libtracker-common/tracker-log.c
+++ b/src/libtracker-common/tracker-log.c
@@ -140,14 +140,22 @@ tracker_log_handler (const gchar    *domain,
 }
 
 gboolean
-tracker_log_init (const gchar *filename,
-		  gint	       this_verbosity)
+tracker_log_init (gint    this_verbosity,
+		  gchar **used_filename)
 {
-	g_return_val_if_fail (filename != NULL, FALSE);
+	gchar *filename;
+	gchar *basename;
 
 	if (initialized) {
 		return TRUE;
 	}
+		
+	basename = g_strdup_printf ("%s.log", g_get_application_name ());
+	filename = g_build_filename (g_get_user_data_dir (), 
+				     "tracker", 
+				     basename, 
+				     NULL);
+	g_free (basename);
 
 	/* Remove previous log */
 	g_unlink (filename);
@@ -177,6 +185,12 @@ tracker_log_init (const gchar *filename,
 
 	g_log_set_default_handler (tracker_log_handler, NULL);
 
+	if (used_filename) {
+		*used_filename = filename;
+	} else {
+		g_free (filename);
+	}
+
 	initialized = TRUE;
 
 	return TRUE;
diff --git a/src/libtracker-common/tracker-log.h b/src/libtracker-common/tracker-log.h
index af2855d..f47733b 100644
--- a/src/libtracker-common/tracker-log.h
+++ b/src/libtracker-common/tracker-log.h
@@ -30,8 +30,8 @@ G_BEGIN_DECLS
 #error "only <libtracker-common/tracker-common.h> must be included directly."
 #endif
 
-gboolean tracker_log_init     (const char *filename,
-			       gint	   verbosity);
+gboolean tracker_log_init     (gint    verbosity,
+			       gchar **used_filename);
 void	 tracker_log_shutdown (void);
 
 G_END_DECLS
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index 214ed8a..c532ca6 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -273,7 +273,7 @@ main (int argc, char *argv[])
 	GOptionContext *context;
 	GError         *error = NULL;
 	TrackerConfig  *config;
-	gchar          *log_filename;
+	gchar          *log_filename = NULL;
 	gboolean        stand_alone = FALSE;
 	guint           log_handler_id = 0;
 
@@ -372,12 +372,6 @@ main (int argc, char *argv[])
 
 	config = tracker_config_new ();
 
-	log_filename =
-		g_build_filename (g_get_user_data_dir (),
-				  "tracker",
-				  "tracker-extract.log",
-				  NULL);
-
 	/* Extractor command line arguments */
 	if (verbosity > -1) {
 		tracker_config_set_verbosity (config, verbosity);
@@ -390,14 +384,15 @@ main (int argc, char *argv[])
 	/* Initialize subsystems */
 	initialize_directories ();
 
-	tracker_log_init (log_filename, tracker_config_get_verbosity (config));
+	tracker_log_init (tracker_config_get_verbosity (config),
+			  &log_filename);
 	g_print ("Starting log:\n  File:'%s'\n", log_filename);
+	g_free (log_filename);
 
 	tracker_thumbnailer_init (config);
 
 	/* Make Tracker available for introspection */
 	if (!tracker_dbus_register_objects ()) {
-		g_free (log_filename);
 		g_object_unref (config);
 
 		return EXIT_FAILURE;
@@ -423,7 +418,6 @@ main (int argc, char *argv[])
 		g_object_unref (hal);
 	}
 
-	g_free (log_filename);
 	g_object_unref (config);
 
 done:
diff --git a/src/tracker-miner-fs/tracker-main.c b/src/tracker-miner-fs/tracker-main.c
index 114e175..60ee9c0 100644
--- a/src/tracker-miner-fs/tracker-main.c
+++ b/src/tracker-miner-fs/tracker-main.c
@@ -219,8 +219,7 @@ main (gint argc, gchar *argv[])
 	TrackerMiner *miner;
 	GOptionContext *context;
 	GError *error = NULL;
-	gchar *filename;
-        gchar *basename;
+	gchar *log_filename = NULL;
 
 	g_type_init ();
 
@@ -277,16 +276,10 @@ main (gint argc, gchar *argv[])
 		return EXIT_FAILURE;
 	}
 
-	basename = g_strdup_printf ("%s.log", g_get_application_name ());
-	filename = g_build_filename (g_get_user_data_dir (), 
-                                     "tracker", 
-                                     basename, 
-                                     NULL);
-	g_free (basename);
-
-	tracker_log_init (filename, tracker_config_get_verbosity (config));
-	g_print ("Starting log:\n  File:'%s'\n", filename);
-	g_free (filename);
+	tracker_log_init (tracker_config_get_verbosity (config),
+                          &log_filename);
+	g_print ("Starting log:\n  File:'%s'\n", log_filename);
+	g_free (log_filename);
 
 	sanity_check_option_values (config);
 
diff --git a/src/tracker-store/tracker-main.c b/src/tracker-store/tracker-main.c
index 1d6389a..4ee0c01 100644
--- a/src/tracker-store/tracker-main.c
+++ b/src/tracker-store/tracker-main.c
@@ -425,13 +425,6 @@ initialize_locations (void)
 		g_build_filename (private->user_data_dir, 
 				  "tracker-userdata-backup.ttl",
 				  NULL);
-
-	/* Private locations */
-	private->log_filename =
-		g_build_filename (g_get_user_data_dir (),
-				  "tracker",
-				  "tracker-store.log",
-				  NULL);
 }
 
 static void
@@ -736,7 +729,8 @@ main (gint argc, gchar *argv[])
 	}
 
 	/* Initialize other subsystems */
-	tracker_log_init (private->log_filename, tracker_config_get_verbosity (config));
+	tracker_log_init (tracker_config_get_verbosity (config),
+			  &private->log_filename);
 	g_print ("Starting log:\n  File:'%s'\n", private->log_filename);
 
 	sanity_check_option_values (config);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]