X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Flog.c;h=cf4d990b6cf1dff659793696be335b8271e3657c;hb=d7644e0fdb5c6ba58091b62a27ba9eda4fd159f0;hp=3a6ab12a26ad2260ed54348ca9f47d28c6ce7110;hpb=5a18b215f7138c0bd59f27389050b0311fa4a549;p=ffmpeg diff --git a/libavutil/log.c b/libavutil/log.c index 3a6ab12a26a..cf4d990b6cf 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -50,7 +50,7 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static int av_log_level = AV_LOG_INFO; static int flags; -#if HAVE_SETCONSOLETEXTATTRIBUTE +#if defined(_WIN32) && !defined(__MINGW32CE__) && HAVE_SETCONSOLETEXTATTRIBUTE #include static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = { [AV_LOG_PANIC /8] = 12, @@ -115,7 +115,7 @@ static int use_color = -1; static void check_color_terminal(void) { -#if HAVE_SETCONSOLETEXTATTRIBUTE +#if defined(_WIN32) && !defined(__MINGW32CE__) && HAVE_SETCONSOLETEXTATTRIBUTE CONSOLE_SCREEN_BUFFER_INFO con_info; con = GetStdHandle(STD_ERROR_HANDLE); use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && @@ -130,7 +130,7 @@ static void check_color_terminal(void) use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && (getenv("TERM") && isatty(2) || getenv("AV_LOG_FORCE_COLOR")); if ( getenv("AV_LOG_FORCE_256COLOR") - || (term && strstr(term, "256color"))); + || (term && strstr(term, "256color"))) use_color *= 256; #else use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && @@ -140,20 +140,24 @@ static void check_color_terminal(void) static void colored_fputs(int level, int tint, const char *str) { + int local_use_color; if (!*str) return; if (use_color < 0) check_color_terminal(); -#if HAVE_SETCONSOLETEXTATTRIBUTE - if (use_color && level != AV_LOG_INFO/8) + if (level == AV_LOG_INFO/8) local_use_color = 0; + else local_use_color = use_color; + +#if defined(_WIN32) && !defined(__MINGW32CE__) && HAVE_SETCONSOLETEXTATTRIBUTE + if (local_use_color) SetConsoleTextAttribute(con, background | color[level]); fputs(str, stderr); - if (use_color && level != AV_LOG_INFO/8) + if (local_use_color) SetConsoleTextAttribute(con, attr_orig); #else - if (use_color == 1 && level != AV_LOG_INFO/8) { + if (local_use_color == 1) { fprintf(stderr, "\033[%d;3%dm%s\033[0m", (color[level] >> 4) & 15, @@ -165,7 +169,7 @@ static void colored_fputs(int level, int tint, const char *str) (color[level] >> 16) & 0xff, tint, str); - } else if (use_color == 256 && level != AV_LOG_INFO/8) { + } else if (local_use_color == 256) { fprintf(stderr, "\033[48;5;%dm\033[38;5;%dm%s\033[0m", (color[level] >> 16) & 0xff, @@ -258,10 +262,12 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) char line[LINE_SZ]; static int is_atty; int type[2]; - unsigned tint = level & 0xff00; - - level &= 0xff; + unsigned tint = 0; + if (level >= 0) { + tint = level & 0xff00; + level &= 0xff; + } if (level > av_log_level) return; @@ -339,6 +345,11 @@ void av_log_set_flags(int arg) flags = arg; } +int av_log_get_flags(void) +{ + return flags; +} + void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) { av_log_callback = callback; @@ -375,3 +386,26 @@ void avpriv_report_missing_feature(void *avc, const char *msg, ...) missing_feature_sample(0, avc, msg, argument_list); va_end(argument_list); } + +#ifdef TEST +// LCOV_EXCL_START +#include + +int main(int argc, char **argv) +{ + int i; + av_log_set_level(AV_LOG_DEBUG); + for (use_color=0; use_color<=256; use_color = 255*use_color+1) { + av_log(NULL, AV_LOG_FATAL, "use_color: %d\n", use_color); + for (i = AV_LOG_DEBUG; i>=AV_LOG_QUIET; i-=8) { + av_log(NULL, i, " %d", i); + av_log(NULL, AV_LOG_INFO, "e "); + av_log(NULL, i + 256*123, "C%d", i); + av_log(NULL, AV_LOG_INFO, "e"); + } + av_log(NULL, AV_LOG_PANIC, "\n"); + } + return 0; +} +// LCOV_EXCL_STOP +#endif