[vlmc-devel] [PATCH] MLTBackend: Add MLT service info in logHandler
Pawel Golinski
golpaw1 at gmail.com
Fri Jul 29 13:27:41 CEST 2016
---
src/Backend/MLT/MLTBackend.cpp | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/Backend/MLT/MLTBackend.cpp b/src/Backend/MLT/MLTBackend.cpp
index 3d39930..62bfc9a 100644
--- a/src/Backend/MLT/MLTBackend.cpp
+++ b/src/Backend/MLT/MLTBackend.cpp
@@ -28,10 +28,13 @@
#include <mlt++/MltRepository.h>
#include <mlt/framework/mlt_log.h>
+#include <mlt/framework/mlt_service.h>
+#include <mlt/framework/mlt_properties.h>
#include "MLTFilter.h"
#include <mutex>
+#include <cstring>
#include "Tools/VlmcDebug.h"
#include "vlmc.h"
@@ -101,8 +104,22 @@ void
MLTBackend::setLogHandler( IBackend::LogHandler logHandler )
{
staticLogHandler = logHandler;
- mlt_log_set_callback( []( void*, int level, const char* format, va_list vl )
+ mlt_log_set_callback( []( void* ptr, int level, const char* format, va_list vl )
{
+ char* prefix_buffer = nullptr;
+
+ mlt_properties properties = ptr ? MLT_SERVICE_PROPERTIES( ( mlt_service )ptr ) : NULL;
+
+ if ( properties )
+ {
+ char *mlt_type = mlt_properties_get( properties, "mlt_type" );
+ char *mlt_service = mlt_properties_get( properties, "mlt_service" );
+ if ( mlt_service )
+ asprintf( &prefix_buffer, "[%s %s] ", mlt_type, mlt_service );
+ else
+ asprintf( &prefix_buffer, "[%s %p] ", mlt_type, ptr );
+ }
+
char* buffer = nullptr;
auto lvl = IBackend::None;
@@ -118,6 +135,18 @@ MLTBackend::setLogHandler( IBackend::LogHandler logHandler )
if ( vasprintf( &buffer, format, vl ) < 0 )
return;
+ if ( prefix_buffer )
+ {
+ size_t msg_size = strlen( prefix_buffer ) + strlen( buffer ) + 1;
+ prefix_buffer = ( char* )realloc( prefix_buffer, msg_size * sizeof( char ) );
+ if ( prefix_buffer != NULL )
+ {
+ strcat( prefix_buffer, buffer );
+ free( buffer );
+ buffer = prefix_buffer;
+ }
+ }
+
staticLogHandler( lvl, buffer );
free( buffer );
} );
--
2.7.4 (Apple Git-66)
More information about the Vlmc-devel
mailing list