[vlmc-devel] Fix Qt log hook

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 00:31:19 2014 +0200| [4c22bfd7ae9e61c20bf15372e57f710566cbe286] | committer: Hugo Beauzée-Luyssen

Fix Qt log hook

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

 src/Tools/VlmcDebug.cpp |   23 +++++++++++++----------
 src/Tools/VlmcDebug.h   |   12 ++++++++----
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/Tools/VlmcDebug.cpp b/src/Tools/VlmcDebug.cpp
index fd15f5c..c975a55 100644
--- a/src/Tools/VlmcDebug.cpp
+++ b/src/Tools/VlmcDebug.cpp
@@ -32,11 +32,12 @@ VlmcDebug::VlmcDebug() : m_logFile( NULL )
     VLMC_CREATE_PRIVATE_PREFERENCE_INT( "private/LogLevel", 0 );
     QStringList args = qApp->arguments();
     if ( args.indexOf( QRegExp( "-vv+" ) ) >= 0 )
-        SettingsManager::getInstance()->setValue( "private/LogLevel", VlmcDebug::Debug, SettingsManager::Vlmc );
+        m_currentLogLevel = VlmcDebug::Debug;
     else if ( args.contains( "-v" ) == true )
-        SettingsManager::getInstance()->setValue( "private/LogLevel", VlmcDebug::Verbose, SettingsManager::Vlmc );
+        m_currentLogLevel = VlmcDebug::Verbose;
     else
-        SettingsManager::getInstance()->setValue( "private/LogLevel", VlmcDebug::Quiet, SettingsManager::Vlmc );
+        m_currentLogLevel = VlmcDebug::Quiet;
+    SettingsManager::getInstance()->setValue( "private/LogLevel", m_currentLogLevel, SettingsManager::Vlmc );
 
 //    int pos = args.indexOf( QRegExp( "--logfile=.*" ) );
 //    if ( pos > 0 )
@@ -74,7 +75,7 @@ VlmcDebug::~VlmcDebug()
 void
 VlmcDebug::setup()
 {
-//    qInstallMsgHandler( VlmcDebug::vlmcMessageHandler );
+    qInstallMsgHandler( VlmcDebug::vlmcMessageHandler );
 }
 
 void
@@ -99,14 +100,16 @@ VlmcDebug::logFileChanged( const QVariant& logFileV )
 void
 VlmcDebug::vlmcMessageHandler( QtMsgType type, const char* msg )
 {
-    if ( VlmcDebug::getInstance()->m_logFile != NULL )
+    //FIXME: This is ok as long as we guarantee no log messages will happen after we
+    // uninstall the hook
+    VlmcDebug* self = VlmcDebug::getInstance();
+    if ( self->m_logFile != NULL )
     {
-        VlmcDebug::getInstance()->m_logFile->write( msg );
-        VlmcDebug::getInstance()->m_logFile->write( "\n" );
+        self->m_logFile->write( msg );
+        self->m_logFile->write( "\n" );
     }
-//    if ( type != QtFatalMsg
-//         && type < SettingsManager::getInstance()->value( "private/LogLevel", QtDebugMsg, SettingsManager::Vlmc ).toInt() )
-//        return ;
+    if ( (int)type < (int)self->m_currentLogLevel )
+        return ;
     switch ( type )
     {
     case QtDebugMsg:
diff --git a/src/Tools/VlmcDebug.h b/src/Tools/VlmcDebug.h
index 7d2fb68..979ffde 100644
--- a/src/Tools/VlmcDebug.h
+++ b/src/Tools/VlmcDebug.h
@@ -38,11 +38,14 @@ class   VlmcDebug : public QObject, public Singleton<VlmcDebug>
     Q_OBJECT
 
     public:
-        enum    VerboseLevel
+        // Keep the same order as Qt's message levels, since that's what we're
+        // going to use for comparing log levels in the message handler
+        enum    LogLevel
         {
-            Quiet,
-            Verbose,
-            Debug
+            Debug = QtDebugMsg,
+            Verbose = QtWarningMsg,
+            // This means both qCritical() & qFatal() will be displayed in quiet mode
+            Quiet = QtCriticalMsg,
         };
 
         static void     vlmcMessageHandler( QtMsgType type, const char* msg );
@@ -52,6 +55,7 @@ class   VlmcDebug : public QObject, public Singleton<VlmcDebug>
         virtual ~VlmcDebug();
 
         QFile*          m_logFile;
+        LogLevel        m_currentLogLevel;
 
     private slots:
         void            logFileChanged( const QVariant& logFile );



More information about the Vlmc-devel mailing list