comparison log.c @ 901:5b60f5ff30da libavutil

Coloring the log with ANSI. Ive checked this on black and white background and found no problem in terms of readability. flames welcome.
author michael
date Thu, 22 Apr 2010 18:58:39 +0000
parents 0795a743bda1
children 143b937b0b03
comparison
equal deleted inserted replaced
900:5dcfac995af3 901:5b60f5ff30da
22 /** 22 /**
23 * @file 23 * @file
24 * logging functions 24 * logging functions
25 */ 25 */
26 26
27 #include <unistd.h>
27 #include "avutil.h" 28 #include "avutil.h"
28 #include "log.h" 29 #include "log.h"
29 30
30 #if LIBAVUTIL_VERSION_MAJOR > 50 31 #if LIBAVUTIL_VERSION_MAJOR > 50
31 static 32 static
32 #endif 33 #endif
33 int av_log_level = AV_LOG_INFO; 34 int av_log_level = AV_LOG_INFO;
34 35
36 #if !HAVE_ISATTY
37 #define isatty(s) 0
38 #endif
39
40 #undef fprintf
41 static void colored_fputs(int color, const char *str){
42 if(isatty(2)){
43 fprintf(stderr, "\033[%dm\033[3%dm", color>>4, color&15);
44 }
45 fputs(str, stderr);
46 if(isatty(2)){
47 fprintf(stderr, "\033[0m");
48 }
49 }
50
35 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) 51 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
36 { 52 {
37 static int print_prefix=1; 53 static int print_prefix=1;
38 static int count; 54 static int count;
39 static char line[1024], prev[1024]; 55 static char line[1024], prev[1024];
56 static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9};
40 AVClass* avc= ptr ? *(AVClass**)ptr : NULL; 57 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
41 if(level>av_log_level) 58 if(level>av_log_level)
42 return; 59 return;
43 #undef fprintf 60 #undef fprintf
44 if(print_prefix && avc) { 61 if(print_prefix && avc) {
55 } 72 }
56 if(count>0){ 73 if(count>0){
57 fprintf(stderr, " Last message repeated %d times\n", count); 74 fprintf(stderr, " Last message repeated %d times\n", count);
58 count=0; 75 count=0;
59 } 76 }
60 fputs(line, stderr); 77 colored_fputs(color[av_clip(level>>3, 0, 6)], line);
61 strcpy(prev, line); 78 strcpy(prev, line);
62 } 79 }
63 80
64 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; 81 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
65 82