Mercurial > libavutil.hg
comparison log.c @ 935:096294624d52 libavutil
Move ansi color array to outside of av_log_default_callback(). Do not pass
ansi color code to colored_fputs(), and pass instead the error level so the
proper color code may be used.
author | ramiro |
---|---|
date | Wed, 09 Jun 2010 18:10:35 +0000 |
parents | 252d7a7ee7d5 |
children | 41b43a526d0d |
comparison
equal
deleted
inserted
replaced
934:252d7a7ee7d5 | 935:096294624d52 |
---|---|
32 #if LIBAVUTIL_VERSION_MAJOR > 50 | 32 #if LIBAVUTIL_VERSION_MAJOR > 50 |
33 static | 33 static |
34 #endif | 34 #endif |
35 int av_log_level = AV_LOG_INFO; | 35 int av_log_level = AV_LOG_INFO; |
36 | 36 |
37 static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; | |
37 static int use_color=-1; | 38 static int use_color=-1; |
38 | 39 |
39 #undef fprintf | 40 #undef fprintf |
40 static void colored_fputs(int color, const char *str){ | 41 static void colored_fputs(int level, const char *str){ |
41 if(use_color<0){ | 42 if(use_color<0){ |
42 #if HAVE_ISATTY && !defined(_WIN32) | 43 #if HAVE_ISATTY && !defined(_WIN32) |
43 use_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2); | 44 use_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2); |
44 #else | 45 #else |
45 use_color= 0; | 46 use_color= 0; |
46 #endif | 47 #endif |
47 } | 48 } |
48 | 49 |
49 if(use_color){ | 50 if(use_color){ |
50 fprintf(stderr, "\033[%d;3%dm", color>>4, color&15); | 51 fprintf(stderr, "\033[%d;3%dm", color[level]>>4, color[level]&15); |
51 } | 52 } |
52 fputs(str, stderr); | 53 fputs(str, stderr); |
53 if(use_color){ | 54 if(use_color){ |
54 fprintf(stderr, "\033[0m"); | 55 fprintf(stderr, "\033[0m"); |
55 } | 56 } |
62 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) | 63 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) |
63 { | 64 { |
64 static int print_prefix=1; | 65 static int print_prefix=1; |
65 static int count; | 66 static int count; |
66 static char line[1024], prev[1024]; | 67 static char line[1024], prev[1024]; |
67 static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; | |
68 AVClass* avc= ptr ? *(AVClass**)ptr : NULL; | 68 AVClass* avc= ptr ? *(AVClass**)ptr : NULL; |
69 if(level>av_log_level) | 69 if(level>av_log_level) |
70 return; | 70 return; |
71 line[0]=0; | 71 line[0]=0; |
72 #undef fprintf | 72 #undef fprintf |
89 } | 89 } |
90 if(count>0){ | 90 if(count>0){ |
91 fprintf(stderr, " Last message repeated %d times\n", count); | 91 fprintf(stderr, " Last message repeated %d times\n", count); |
92 count=0; | 92 count=0; |
93 } | 93 } |
94 colored_fputs(color[av_clip(level>>3, 0, 6)], line); | 94 colored_fputs(av_clip(level>>3, 0, 6), line); |
95 strcpy(prev, line); | 95 strcpy(prev, line); |
96 } | 96 } |
97 | 97 |
98 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; | 98 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; |
99 | 99 |