[tracker] libtracker-common: Fixed logging so G_LOG_LEVEL_INFO is verbosity=1



commit c467c574ecbc209aa93a67ba1146d60fd12883cc
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Oct 27 13:03:20 2009 +0000

    libtracker-common: Fixed logging so G_LOG_LEVEL_INFO is verbosity=1

 src/libtracker-common/tracker-log.c |   53 ++++++++++++++++++++++++++++++++--
 src/libtracker-common/tracker-log.h |   11 +++----
 2 files changed, 54 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-common/tracker-log.c b/src/libtracker-common/tracker-log.c
index a3dbac3..6030cc0 100644
--- a/src/libtracker-common/tracker-log.c
+++ b/src/libtracker-common/tracker-log.c
@@ -126,9 +126,7 @@ tracker_log_handler (const gchar    *domain,
 		     const gchar    *message,
 		     gpointer	     user_data)
 {
-	if (((log_level & G_LOG_LEVEL_DEBUG) && verbosity < 3) ||
-	    ((log_level & G_LOG_LEVEL_INFO) && verbosity < 2) ||
-	    ((log_level & G_LOG_LEVEL_MESSAGE) && verbosity < 1)) {
+	if (!tracker_log_should_handle (log_level, verbosity)) {
 		return;
 	}
 
@@ -173,7 +171,7 @@ tracker_log_init (gint    this_verbosity,
 			   "All logging will go to stderr\n");
 	}
 
-	verbosity = this_verbosity;
+	verbosity = CLAMP (this_verbosity, 0, 3);
 	mutex = g_mutex_new ();
 
 	/* Add log handler function */
@@ -213,3 +211,50 @@ tracker_log_shutdown (void)
 
 	initialized = FALSE;
 }
+
+gboolean
+tracker_log_should_handle (GLogLevelFlags log_level,
+			   gint           this_verbosity)
+{
+	switch (this_verbosity) {
+	/* Log level 3: EVERYTHING */
+	case 3:
+		break;
+
+	/* Log level 2: CRITICAL/ERROR/WARNING/INFO/MESSAGE only */
+	case 2:
+		if (!(log_level & G_LOG_LEVEL_MESSAGE) &&
+		    !(log_level & G_LOG_LEVEL_INFO) &&
+		    !(log_level & G_LOG_LEVEL_WARNING) &&
+		    !(log_level & G_LOG_LEVEL_ERROR) &&
+		    !(log_level & G_LOG_LEVEL_CRITICAL)) {
+			return FALSE;
+		}
+
+		break;
+
+	/* Log level 1: CRITICAL/ERROR/WARNING/INFO only */
+	case 1:
+		if (!(log_level & G_LOG_LEVEL_INFO) &&
+		    !(log_level & G_LOG_LEVEL_WARNING) &&
+		    !(log_level & G_LOG_LEVEL_ERROR) &&
+		    !(log_level & G_LOG_LEVEL_CRITICAL)) {
+			return FALSE;
+		}
+
+		break;
+
+	/* Log level 0: CRITICAL/ERROR/WARNING only (default) */
+	default:
+	case 0:
+		if (!(log_level & G_LOG_LEVEL_WARNING) &&
+		    !(log_level & G_LOG_LEVEL_ERROR) &&
+		    !(log_level & G_LOG_LEVEL_CRITICAL)) {
+			return FALSE;
+		}
+
+		break;
+	}
+
+	return TRUE;
+}
diff --git a/src/libtracker-common/tracker-log.h b/src/libtracker-common/tracker-log.h
index 3183a12..90d2579 100644
--- a/src/libtracker-common/tracker-log.h
+++ b/src/libtracker-common/tracker-log.h
@@ -52,12 +52,11 @@ tracker_info (const gchar *format,
 }
 #endif  /* !__GNUC__ */
 
-
-
-
-gboolean tracker_log_init     (gint    verbosity,
-			       gchar **used_filename);
-void	 tracker_log_shutdown (void);
+gboolean tracker_log_init          (gint             verbosity,
+				    gchar          **used_filename);
+void     tracker_log_shutdown      (void);
+gboolean tracker_log_should_handle (GLogLevelFlags   log_level,
+				    gint             verbosity);
 
 G_END_DECLS
 



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