[rygel] core: Ability to specify log level at runtime



commit e86585d56e064da608e587981ccae11c540b7540
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Sep 28 19:24:37 2009 +0300

    core: Ability to specify log level at runtime

 src/rygel/rygel-cmdline-config.vala |   13 +++++++++++++
 src/rygel/rygel-configuration.vala  |    2 ++
 src/rygel/rygel-log-handler.vala    |    5 ++++-
 src/rygel/rygel-meta-config.vala    |   19 +++++++++++++++++++
 src/rygel/rygel-user-config.vala    |    8 ++++++++
 5 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/src/rygel/rygel-cmdline-config.vala b/src/rygel/rygel-cmdline-config.vala
index 962b156..11597a0 100644
--- a/src/rygel/rygel-cmdline-config.vala
+++ b/src/rygel/rygel-cmdline-config.vala
@@ -41,6 +41,8 @@ public class Rygel.CmdlineConfig : GLib.Object, Configuration {
     private static bool no_mp2ts_trans;
     private static bool no_lpcm_trans;
 
+    private static LogLevel log_level = LogLevel.INVALID;
+
     private static bool version;
 
     [CCode (array_length = false, array_null_terminated = true)]
@@ -73,6 +75,9 @@ public class Rygel.CmdlineConfig : GLib.Object, Configuration {
           "Disable mpeg2 transport stream transcoder", null },
         { "disable-lpcm-transcoder", 'l', 0, OptionArg.NONE, ref no_lpcm_trans,
           "Disable Linear PCM transcoder", null },
+        { "log-level", 'g', 0, OptionArg.INT, ref log_level,
+          "Log level. 1=critical,2=error,3=warning,4=message/info,5=debug",
+          "N" },
         { "disable-plugin", 'd', 0, OptionArg.STRING_ARRAY,
           ref disabled_plugins,
           "Disable plugin", "PluginName" },
@@ -144,6 +149,14 @@ public class Rygel.CmdlineConfig : GLib.Object, Configuration {
         return !no_lpcm_trans;
     }
 
+    public LogLevel get_log_level () throws GLib.Error {
+        if (this.log_level == LogLevel.INVALID) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return log_level;
+    }
+
     public bool get_enabled (string section) throws GLib.Error {
         var disabled = false;
         foreach (var plugin in disabled_plugins) {
diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala
index f10dfd5..bb9937d 100644
--- a/src/rygel/rygel-configuration.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -47,6 +47,8 @@ public interface Rygel.Configuration : GLib.Object {
 
     public abstract bool get_lpcm_transcoder () throws GLib.Error;
 
+    public abstract LogLevel get_log_level () throws GLib.Error;
+
     public abstract bool get_enabled (string section) throws GLib.Error;
 
     public abstract string get_title (string section) throws GLib.Error;
diff --git a/src/rygel/rygel-log-handler.vala b/src/rygel/rygel-log-handler.vala
index 81669f2..d56d490 100644
--- a/src/rygel/rygel-log-handler.vala
+++ b/src/rygel/rygel-log-handler.vala
@@ -58,7 +58,10 @@ public class Rygel.LogHandler : GLib.Object {
                          LogLevelFlags.FLAG_RECURSION,
                          this.log_func);
 
-        this.levels = DEFAULT_LEVELS;
+        // Get the allowed log levels from the config
+        var config = MetaConfig.get_default ();
+
+        this.levels = this.log_level_to_flags (config.get_log_level ());
     }
 
     private void log_func (string?       log_domain,
diff --git a/src/rygel/rygel-meta-config.vala b/src/rygel/rygel-meta-config.vala
index 629d399..90e2d4e 100644
--- a/src/rygel/rygel-meta-config.vala
+++ b/src/rygel/rygel-meta-config.vala
@@ -191,6 +191,25 @@ public class Rygel.MetaConfig : GLib.Object, Configuration {
         return val;
     }
 
+    public LogLevel get_log_level () throws GLib.Error {
+        LogLevel val = LogLevel.DEFAULT;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_log_level ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
     public bool get_enabled (string section) throws GLib.Error {
         bool val = true;
         bool unavailable = true;
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 8602089..2902d0d 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -39,6 +39,7 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
                                                     "enable-mp2ts-transcoder";
     protected static const string LPCM_TRANSCODER_KEY =
                                                     "enable-lpcm-transcoder";
+    protected static const string LOG_LEVEL_KEY = "log-level";
 
     private const string DBUS_SERVICE = "org.freedesktop.DBus";
     private const string DBUS_PATH = "/org/freedesktop/DBus";
@@ -115,6 +116,13 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
         this.set_bool ("general", LPCM_TRANSCODER_KEY, value);
     }
 
+    public LogLevel get_log_level () throws GLib.Error {
+        return (LogLevel) this.get_int ("general",
+                                        LOG_LEVEL_KEY,
+                                        LogLevel.INVALID,
+                                        LogLevel.DEBUG);
+    }
+
     public static UserConfig get_default () throws Error {
         if (config == null) {
             config = new UserConfig ();



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