]> git.sesse.net Git - mlt/blob - src/framework/mlt_log.c
A little debugging.
[mlt] / src / framework / mlt_log.c
1 /**
2  * \file mlt_log.c
3  * \brief logging functions
4  *
5  * Copyright (c) 2003 Michel Bardiaux
6  *
7  * This file was a part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23
24 #include "mlt_log.h"
25 #include "mlt_service.h"
26
27 #include <string.h>
28
29 static int log_level = MLT_LOG_WARNING;
30
31 void default_callback( void* ptr, int level, const char* fmt, va_list vl )
32 {
33         static int print_prefix = 1;
34         mlt_properties properties = ptr ? MLT_SERVICE_PROPERTIES( ( mlt_service )ptr ) : NULL;
35         
36         if ( level > log_level )
37                 return;
38         if ( print_prefix && properties )
39         {
40                 char *mlt_type = mlt_properties_get( properties, "mlt_type" );
41                 char *mlt_service = mlt_properties_get( properties, "mlt_service" );
42                 char *resource = mlt_properties_get( properties, "resource" );
43         
44                 if ( !( resource && *resource && resource[0] == '<' && resource[ strlen(resource) - 1 ] == '>' ) )
45                         mlt_type = mlt_properties_get( properties, "mlt_type" );
46                 if ( mlt_service )
47                         fprintf( stderr, "[%s %s] ", mlt_type, mlt_service );
48                 else
49                         fprintf( stderr, "[%s %p] ", mlt_type, ptr );
50                 if ( resource )
51                         fprintf( stderr, "%s\n    ", resource );
52         }
53         print_prefix = strstr( fmt, "\n" ) != NULL;
54         vfprintf( stderr, fmt, vl );
55 }
56
57 static void ( *callback )( void*, int, const char*, va_list ) = default_callback;
58
59 void mlt_log( void* service, int level, const char *fmt, ...)
60 {
61         va_list vl;
62         
63         va_start( vl, fmt );
64         mlt_vlog( service, level, fmt, vl );
65         va_end( vl );
66 }
67
68 void mlt_vlog( void* service, int level, const char *fmt, va_list vl )
69 {
70         if ( callback ) callback( service, level, fmt, vl );
71 }
72
73 int mlt_log_get_level( void )
74 {
75         return log_level;
76 }
77
78 void mlt_log_set_level( int level )
79 {
80         log_level = level;
81 }
82
83 void mlt_log_set_callback( void (*new_callback)( void*, int, const char*, va_list ) )
84 {
85         callback = new_callback;
86 }