Constness changes
[melted] / 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_INFO;
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 *resource = mlt_properties_get( properties, "resource" );
42
43 if ( resource && *resource && resource[0] == '<' && resource[ strlen(resource) - 1 ] == '>' )
44 mlt_type = resource;
45 fprintf( stderr, "[%s @ %p]", mlt_type, ptr );
46 }
47 print_prefix = strstr( fmt, "\n" ) != NULL;
48 vfprintf( stderr, fmt, vl );
49 }
50
51 static void ( *callback )( void*, int, const char*, va_list ) = default_callback;
52
53 void mlt_log( void* service, int level, const char *fmt, ...)
54 {
55 va_list vl;
56
57 va_start( vl, fmt );
58 mlt_vlog( service, level, fmt, vl );
59 va_end( vl );
60 }
61
62 void mlt_vlog( void* service, int level, const char *fmt, va_list vl )
63 {
64 if ( callback ) callback( service, level, fmt, vl );
65 }
66
67 int mlt_log_get_level( void )
68 {
69 return log_level;
70 }
71
72 void mlt_log_set_level( int level )
73 {
74 log_level = level;
75 }
76
77 void mlt_log_set_callback( void (*new_callback)( void*, int, const char*, va_list ) )
78 {
79 callback = new_callback;
80 }