00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avutil.h"
00028 #include "log.h"
00029
00030 int av_log_level = AV_LOG_INFO;
00031
00032 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
00033 {
00034 static int print_prefix=1;
00035 static int count;
00036 static char prev[1024];
00037 char line[1024];
00038 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
00039 if(level>av_log_level)
00040 return;
00041 #undef fprintf
00042 if(print_prefix && avc) {
00043 snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
00044 }else
00045 line[0]=0;
00046
00047 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
00048
00049 print_prefix= line[strlen(line)-1] == '\n';
00050 if(print_prefix && !strcmp(line, prev)){
00051 count++;
00052 return;
00053 }
00054 if(count>0){
00055 fprintf(stderr, " Last message repeated %d times\n", count);
00056 count=0;
00057 }
00058 fputs(line, stderr);
00059 strcpy(prev, line);
00060 }
00061
00062 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
00063
00064 void av_log(void* avcl, int level, const char *fmt, ...)
00065 {
00066 va_list vl;
00067 va_start(vl, fmt);
00068 av_vlog(avcl, level, fmt, vl);
00069 va_end(vl);
00070 }
00071
00072 void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
00073 {
00074 av_log_callback(avcl, level, fmt, vl);
00075 }
00076
00077 int av_log_get_level(void)
00078 {
00079 return av_log_level;
00080 }
00081
00082 void av_log_set_level(int level)
00083 {
00084 av_log_level = level;
00085 }
00086
00087 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
00088 {
00089 av_log_callback = callback;
00090 }