comparison log.c @ 1017:fd2dd26fab8a libavutil

Limit av_log repeat detection to terminals so as to avoid filling files with lots of mess.
author michael
date Tue, 14 Sep 2010 00:17:58 +0000
parents 00ee3f0ffe6d
children 4a16166d580e
comparison
equal deleted inserted replaced
1016:4c26dcb90bc6 1017:fd2dd26fab8a
83 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) 83 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
84 { 84 {
85 static int print_prefix=1; 85 static int print_prefix=1;
86 static int count; 86 static int count;
87 static char line[1024], prev[1024]; 87 static char line[1024], prev[1024];
88 static int detect_repeats;
88 AVClass* avc= ptr ? *(AVClass**)ptr : NULL; 89 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
89 if(level>av_log_level) 90 if(level>av_log_level)
90 return; 91 return;
91 line[0]=0; 92 line[0]=0;
92 #undef fprintf 93 #undef fprintf
101 } 102 }
102 103
103 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); 104 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
104 105
105 print_prefix= line[strlen(line)-1] == '\n'; 106 print_prefix= line[strlen(line)-1] == '\n';
106 if(print_prefix && !strcmp(line, prev)){ 107
108 #if HAVE_ISATTY
109 if(!detect_repeats) detect_repeats= isatty(2) ? 1 : -1;
110 #endif
111
112 if(print_prefix && detect_repeats==1 && !strcmp(line, prev)){
107 count++; 113 count++;
108 fprintf(stderr, " Last message repeated %d times\r", count); 114 fprintf(stderr, " Last message repeated %d times\r", count);
109 return; 115 return;
110 } 116 }
111 if(count>0){ 117 if(count>0){