[vlmc-devel] VLCInstance: Hook to VLC's logs to aggregate them in vlmc's logfile

Hugo Beauzée-Luyssen git at videolan.org
Sun Feb 16 13:41:25 CET 2014


vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sun Feb 16 14:36:58 2014 +0200| [709389e3aabf8b68645a8cb70c453eb573786544] | committer: Hugo Beauzée-Luyssen

VLCInstance: Hook to VLC's logs to aggregate them in vlmc's logfile

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

 src/LibVLCpp/VLCInstance.cpp |   26 ++++++++++++++++++++++++++
 src/LibVLCpp/VLCInstance.h   |    3 ++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/LibVLCpp/VLCInstance.cpp b/src/LibVLCpp/VLCInstance.cpp
index 86ccecb..5cfb7e2 100644
--- a/src/LibVLCpp/VLCInstance.cpp
+++ b/src/LibVLCpp/VLCInstance.cpp
@@ -25,9 +25,12 @@
 
 #include "SettingsManager.h"
 #include "VlmcLogger.h"
+#include "VlmcDebug.h"
 
 #include <QVector>
 
+#include <cstdio>
+
 using namespace LibVLCpp;
 
 Instance::Instance( QObject* parent /*= NULL*/ ) : QObject( parent )
@@ -48,6 +51,7 @@ Instance::Instance( QObject* parent /*= NULL*/ ) : QObject( parent )
         argv << "-v";
 
     m_internalPtr = libvlc_new( argv.count(), &argv.front() );
+    libvlc_log_set( *this, vlcLogHook, this );
     Q_ASSERT_X( m_internalPtr != NULL, "LibVLCpp::Instance::Instance()",
                 "Can't launch VLMC without a valid LibVLC instance. Please check your VLC installation" );
 }
@@ -56,3 +60,25 @@ Instance::~Instance()
 {
     libvlc_release( m_internalPtr );
 }
+
+void Instance::vlcLogHook(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args)
+{
+    Q_UNUSED( data )
+    Q_UNUSED( ctx )
+
+    char* msg;
+    if (vasprintf( &msg, fmt, args ) < 0 )
+        return;
+    if ( level <= LIBVLC_NOTICE )
+        vlmcDebug() << "[VLC]" << msg;
+    else if ( level == LIBVLC_WARNING )
+        vlmcWarning() << "[VLC]" << msg;
+    else if ( level == LIBVLC_ERROR )
+        vlmcCritical() << "[VLC]" << msg;
+    else
+    {
+        vlmcCritical() << "Unexpected logging level for VLC log" << level;
+        vlmcCritical() << "[VLC]" << msg;
+    }
+    free( msg );
+}
diff --git a/src/LibVLCpp/VLCInstance.h b/src/LibVLCpp/VLCInstance.h
index 8c6afa4..84eae57 100644
--- a/src/LibVLCpp/VLCInstance.h
+++ b/src/LibVLCpp/VLCInstance.h
@@ -43,9 +43,10 @@ namespace LibVLCpp
     private:
         Instance( QObject* parent = NULL );
         Instance( int argc, const char** argv );
-
         ~Instance();
 
+        static void     vlcLogHook( void* data, int level, const libvlc_log_t* ctx, const char* fmt, va_list args );
+
     private:
         friend class    Singleton<Instance>;
     };



More information about the Vlmc-devel mailing list