81
|
1 /*
|
|
2 * log functions
|
|
3 * Copyright (c) 2003 Michel Bardiaux
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 */
|
|
19
|
|
20 /**
|
|
21 * @file log.c
|
|
22 * log.
|
|
23 */
|
|
24
|
|
25 #include "avutil.h"
|
|
26
|
|
27 static int av_log_level = AV_LOG_INFO;
|
|
28
|
|
29 static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
|
30 {
|
|
31 static int print_prefix=1;
|
|
32 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
|
|
33 if(level>av_log_level)
|
|
34 return;
|
|
35 #undef fprintf
|
|
36 if(print_prefix && avc) {
|
|
37 fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
|
|
38 }
|
|
39 #define fprintf please_use_av_log
|
|
40
|
|
41 print_prefix= strstr(fmt, "\n") != NULL;
|
|
42
|
|
43 vfprintf(stderr, fmt, vl);
|
|
44 }
|
|
45
|
|
46 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
|
|
47
|
|
48 void av_log(void* avcl, int level, const char *fmt, ...)
|
|
49 {
|
|
50 va_list vl;
|
|
51 va_start(vl, fmt);
|
|
52 av_vlog(avcl, level, fmt, vl);
|
|
53 va_end(vl);
|
|
54 }
|
|
55
|
|
56 void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
|
|
57 {
|
|
58 av_log_callback(avcl, level, fmt, vl);
|
|
59 }
|
|
60
|
|
61 int av_log_get_level(void)
|
|
62 {
|
|
63 return av_log_level;
|
|
64 }
|
|
65
|
|
66 void av_log_set_level(int level)
|
|
67 {
|
|
68 av_log_level = level;
|
|
69 }
|
|
70
|
|
71 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
|
|
72 {
|
|
73 av_log_callback = callback;
|
|
74 }
|