[vlmc-devel] [PATCH] MLTBackend: Add MLT service info in logHandler
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Fri Jul 29 18:10:42 CEST 2016
On 07/29/2016 05:01 PM, Pawel Golinski wrote:
> ---
> src/Backend/MLT/MLTBackend.cpp | 26 ++++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/src/Backend/MLT/MLTBackend.cpp b/src/Backend/MLT/MLTBackend.cpp
> index 3d39930..015de8e 100644
> --- a/src/Backend/MLT/MLTBackend.cpp
> +++ b/src/Backend/MLT/MLTBackend.cpp
> @@ -28,6 +28,7 @@
> #include <mlt++/MltRepository.h>
>
> #include <mlt/framework/mlt_log.h>
> +#include <mlt/framework/mlt_service.h>
>
> #include "MLTFilter.h"
>
> @@ -101,8 +102,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( mlt_service_properties( ( mlt_service )ptr ) );
> +
> + if ( properties.is_valid() )
> + {
> + char *mlt_type = properties.get( "mlt_type" );
> + char *mlt_service = properties.get( "mlt_service" );
> + if ( mlt_service )
> + asprintf( &prefix_buffer, "[%s %s] ", mlt_type, mlt_service );
> + else
> + asprintf( &prefix_buffer, "[%s %p] ", mlt_type, ptr );
Those asprintf calls should be avoided:
You can't assume asprintf will be available on the target system, as
it's a GNU extension (the same is true for vasprintf, but manually
handling the va_arg probably isn't something you want to do :) )
One could also argue that asprintf can fail and that it's not checked.
std::string can also fail, but in a much less silent way.
> + }
> +
> char* buffer = nullptr;
>
> auto lvl = IBackend::None;
> @@ -118,7 +133,14 @@ MLTBackend::setLogHandler( IBackend::LogHandler logHandler )
> if ( vasprintf( &buffer, format, vl ) < 0 )
> return;
>
> - staticLogHandler( lvl, buffer );
> + std::string msg_str;
> + if ( prefix_buffer )
> + msg_str += prefix_buffer;
> + if ( buffer )
> + msg_str += buffer;
> +
> + staticLogHandler( lvl, msg_str.c_str() );
> + free( prefix_buffer );
> free( buffer );
> } );
> }
>
More information about the Vlmc-devel
mailing list