[vlmc-devel] VlmcDebug: Allow loglevel to change dynamicly

Hugo Beauzée-Luyssen git at videolan.org
Sat Feb 8 00:47:07 CET 2014


vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sat Feb  8 01:40:29 2014 +0200| [9879871c070025f06c47736c72fdae60951ca07f] | committer: Hugo Beauzée-Luyssen

VlmcDebug: Allow loglevel to change dynamicly

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=9879871c070025f06c47736c72fdae60951ca07f
---

 src/Tools/VlmcDebug.cpp |   28 ++++++++++++++++++++++++----
 src/Tools/VlmcDebug.h   |    1 +
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/Tools/VlmcDebug.cpp b/src/Tools/VlmcDebug.cpp
index c975a55..641610d 100644
--- a/src/Tools/VlmcDebug.cpp
+++ b/src/Tools/VlmcDebug.cpp
@@ -29,7 +29,13 @@
 VlmcDebug::VlmcDebug() : m_logFile( NULL )
 {
     //setup log level :
-    VLMC_CREATE_PRIVATE_PREFERENCE_INT( "private/LogLevel", 0 );
+    {
+        SettingValue* logLevel = VLMC_CREATE_PREFERENCE( SettingValue::Int, "private/LogLevel", (int)VlmcDebug::Quiet,
+                                                        "", "", SettingValue::Private | SettingValue::Clamped );
+        logLevel->setLimits((int)Debug, (int)Verbose);
+        // Purposedly destroying the setting value, as we need to use the manager for other operations.
+        //FIXME: Actually I'm not sure for setting the value since this is a private variable.
+    }
     QStringList args = qApp->arguments();
     if ( args.indexOf( QRegExp( "-vv+" ) ) >= 0 )
         m_currentLogLevel = VlmcDebug::Debug;
@@ -37,7 +43,10 @@ VlmcDebug::VlmcDebug() : m_logFile( NULL )
         m_currentLogLevel = VlmcDebug::Verbose;
     else
         m_currentLogLevel = VlmcDebug::Quiet;
-    SettingsManager::getInstance()->setValue( "private/LogLevel", m_currentLogLevel, SettingsManager::Vlmc );
+    SettingsManager* settingsManager = SettingsManager::getInstance();
+    settingsManager->setValue( "private/LogLevel", m_currentLogLevel, SettingsManager::Vlmc );
+    settingsManager->watchValue( "private/LogLevel", this, SLOT(logLevelChanged( const QVariant& )),
+                                 SettingsManager::Vlmc, Qt::DirectConnection );
 
 //    int pos = args.indexOf( QRegExp( "--logfile=.*" ) );
 //    if ( pos > 0 )
@@ -97,11 +106,22 @@ VlmcDebug::logFileChanged( const QVariant& logFileV )
     m_logFile->open( QFile::Append | QFile::Truncate );
 }
 
+
+void
+VlmcDebug::logLevelChanged( const QVariant &logLevel )
+{
+
+    Q_ASSERT_X(logLevel.toInt() >= (int)VlmcDebug::Debug &&
+               logLevel.toInt() <= (int)VlmcDebug::Quiet,
+               "Setting log level", "Invalid value for log level");
+    m_currentLogLevel = (VlmcDebug::LogLevel)logLevel.toInt();
+}
+
 void
 VlmcDebug::vlmcMessageHandler( QtMsgType type, const char* msg )
 {
-    //FIXME: This is ok as long as we guarantee no log messages will happen after we
-    // uninstall the hook
+    //FIXME: This is ok as long as we guarantee no log message will arrive after
+    // we uninstall the hook
     VlmcDebug* self = VlmcDebug::getInstance();
     if ( self->m_logFile != NULL )
     {
diff --git a/src/Tools/VlmcDebug.h b/src/Tools/VlmcDebug.h
index 979ffde..4062cd7 100644
--- a/src/Tools/VlmcDebug.h
+++ b/src/Tools/VlmcDebug.h
@@ -59,6 +59,7 @@ class   VlmcDebug : public QObject, public Singleton<VlmcDebug>
 
     private slots:
         void            logFileChanged( const QVariant& logFile );
+        void            logLevelChanged( const QVariant& logLevel );
 
         friend class    Singleton<VlmcDebug>;
 };



More information about the Vlmc-devel mailing list