X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Flog.c;h=37427efaf107f2acda7be20bf87a825483353b4e;hb=99684f3ae752fc8bfb44a2dd1482f8d7a3d8536d;hp=c447b5a10fd8f3621af0b7b6efd380a37924090d;hpb=7763118cae4eb468b032dbd29af15a011c2c233b;p=ffmpeg diff --git a/libavutil/log.c b/libavutil/log.c index c447b5a10fd..37427efaf10 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -40,18 +40,28 @@ #include "internal.h" #include "log.h" +#if HAVE_VALGRIND_VALGRIND_H +#include +/* this is the log level at which valgrind will output a full backtrace */ +#define BACKTRACE_LOGLEVEL AV_LOG_ERROR +#endif + static int av_log_level = AV_LOG_INFO; static int flags; +#define NB_LEVELS 8 #if HAVE_SETCONSOLETEXTATTRIBUTE #include -static const uint8_t color[] = { 12, 12, 12, 14, 7, 10, 11 }; +static const uint8_t color[NB_LEVELS] = { 12, 12, 12, 14, 7, 10, 11, 8}; static int16_t background, attr_orig; static HANDLE con; #define set_color(x) SetConsoleTextAttribute(con, background | color[x]) #define reset_color() SetConsoleTextAttribute(con, attr_orig) +#define print_256color(x) #else -static const uint8_t color[] = { 0x41, 0x41, 0x11, 0x03, 9, 0x02, 0x06 }; +static const uint8_t color[NB_LEVELS] = { + 0x41, 0x41, 0x11, 0x03, 9, 0x02, 0x06, 0x07 +}; #define set_color(x) fprintf(stderr, "\033[%d;3%dm", color[x] >> 4, color[x]&15) #define print_256color(x) fprintf(stderr, "\033[38;5;%dm", x) #define reset_color() fprintf(stderr, "\033[0m") @@ -74,7 +84,8 @@ static void check_color_terminal(void) char *term = getenv("TERM"); use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && (getenv("TERM") && isatty(2) || getenv("AV_LOG_FORCE_COLOR")); - use_color += !!strstr(term, "256color") ; + if (use_color) + use_color += term && strstr(term, "256color"); #else use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR"); @@ -117,7 +128,7 @@ void av_log_default_callback(void *avcl, int level, const char *fmt, va_list vl) char line[1024]; static int is_atty; AVClass* avc = avcl ? *(AVClass **) avcl : NULL; - int tint = av_clip(level >> 8, 0, 256); + unsigned tint = level & 0xff00; level &= 0xff; @@ -157,8 +168,13 @@ void av_log_default_callback(void *avcl, int level, const char *fmt, va_list vl) fprintf(stderr, " Last message repeated %d times\n", count); count = 0; } - colored_fputs(av_clip(level >> 3, 0, 6), tint, line); + colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, line); av_strlcpy(prev, line, sizeof line); + +#if CONFIG_VALGRIND_BACKTRACE + if (level <= BACKTRACE_LOGLEVEL) + VALGRIND_PRINTF_BACKTRACE(""); +#endif } static void (*av_log_callback)(void*, int, const char*, va_list) =