From eb7efc126aed1947edcba81c2d1a9bf776206f5c Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 28 May 2012 03:09:55 +0200 Subject: log: color prefixes according to their source. The use of cyan is droped from the levels to avoid confusion magenta/cyan/blue is used for muxer/codec/filter layer Signed-off-by: Michael Niedermayer --- libavutil/log.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 12 deletions(-) (limited to 'libavutil/log.c') diff --git a/libavutil/log.c b/libavutil/log.c index 20db49c..62394ea 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -41,7 +41,16 @@ static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = { [AV_LOG_WARNING/8] = 14, [AV_LOG_INFO /8] = 7, [AV_LOG_VERBOSE/8] = 10, - [AV_LOG_DEBUG /8] = 11, + [AV_LOG_DEBUG /8] = 10, + [16+AV_CLASS_CATEGORY_NA ] = 7, + [16+AV_CLASS_CATEGORY_INPUT ] = 3, + [16+AV_CLASS_CATEGORY_OUTPUT ] = 11, + [16+AV_CLASS_CATEGORY_MUXER ] = 3, + [16+AV_CLASS_CATEGORY_DEMUXER ] = 11, + [16+AV_CLASS_CATEGORY_ENCODER ] = 5, + [16+AV_CLASS_CATEGORY_DECODER ] = 13, + [16+AV_CLASS_CATEGORY_FILTER ] = 1, + [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 9, }; static int16_t background, attr_orig; @@ -57,7 +66,16 @@ static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = { [AV_LOG_WARNING/8] = 0x03, [AV_LOG_INFO /8] = 9, [AV_LOG_VERBOSE/8] = 0x02, - [AV_LOG_DEBUG /8] = 0x06, + [AV_LOG_DEBUG /8] = 0x02, + [16+AV_CLASS_CATEGORY_NA ] = 9, + [16+AV_CLASS_CATEGORY_INPUT ] = 0x06, + [16+AV_CLASS_CATEGORY_OUTPUT ] = 0x16, + [16+AV_CLASS_CATEGORY_MUXER ] = 0x06, + [16+AV_CLASS_CATEGORY_DEMUXER ] = 0x16, + [16+AV_CLASS_CATEGORY_ENCODER ] = 0x05, + [16+AV_CLASS_CATEGORY_DECODER ] = 0x15, + [16+AV_CLASS_CATEGORY_FILTER ] = 0x04, + [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 0x14, }; #define set_color(x) fprintf(stderr, "\033[%d;3%dm", color[x] >> 4, color[x]&15) @@ -111,27 +129,47 @@ static void sanitize(uint8_t *line){ } } -void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, - char *line, int line_size, int *print_prefix) +static int get_category(AVClass *avc){ + if( !avc + || (avc->version&0xFF)<100 + || avc->version < (51 << 16 | 56 << 8) + || avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16; + + return avc->category + 16; +} + +static void format_line(void *ptr, int level, const char *fmt, va_list vl, + char part[3][512], int part_size, int *print_prefix, int type[2]) { AVClass* avc = ptr ? *(AVClass **) ptr : NULL; - line[0] = 0; + part[0][0] = part[1][0] = part[2][0] = 0; + if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; if (*print_prefix && avc) { if (avc->parent_log_context_offset) { AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + avc->parent_log_context_offset); if (parent && *parent) { - snprintf(line, line_size, "[%s @ %p] ", + snprintf(part[0], part_size, "[%s @ %p] ", (*parent)->item_name(parent), parent); + if(type) type[0] = get_category(*parent); } } - snprintf(line + strlen(line), line_size - strlen(line), "[%s @ %p] ", + snprintf(part[1], part_size, "[%s @ %p] ", avc->item_name(ptr), ptr); + if(type) type[1] = get_category(avc); } - vsnprintf(line + strlen(line), line_size - strlen(line), fmt, vl); + vsnprintf(part[2], part_size, fmt, vl); - *print_prefix = strlen(line) && line[strlen(line) - 1] == '\n'; + *print_prefix = strlen(part[2]) && part[2][strlen(part[2]) - 1] == '\n'; +} + +void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, + char *line, int line_size, int *print_prefix) +{ + char part[3][512]; + format_line(ptr, level, fmt, vl, part, sizeof(part[0]), print_prefix, NULL); + snprintf(line, line_size, "%s%s%s", part[0], part[1], part[2]); } void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) @@ -139,12 +177,15 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) static int print_prefix = 1; static int count; static char prev[1024]; + char part[3][512]; char line[1024]; static int is_atty; + int type[2]; if (level > av_log_level) return; - av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); + format_line(ptr, level, fmt, vl, part, sizeof(part[0]), &print_prefix, type); + snprintf(line, sizeof(line), "%s%s%s", part[0], part[1], part[2]); #if HAVE_ISATTY if (!is_atty) @@ -163,8 +204,12 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) count = 0; } strcpy(prev, line); - sanitize(line); - colored_fputs(av_clip(level >> 3, 0, 6), line); + sanitize(part[0]); + colored_fputs(type[0], part[0]); + sanitize(part[1]); + colored_fputs(type[1], part[1]); + sanitize(part[2]); + colored_fputs(av_clip(level >> 3, 0, 6), part[2]); } static void (*av_log_callback)(void*, int, const char*, va_list) = -- cgit v1.1