static int av_log_level = AV_LOG_INFO;
static int flags;
-#if HAVE_SETCONSOLETEXTATTRIBUTE
+#if defined(_WIN32) && !defined(__MINGW32CE__) && HAVE_SETCONSOLETEXTATTRIBUTE
#include <windows.h>
static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = {
[AV_LOG_PANIC /8] = 12,
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") &&
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") &&
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,
(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,
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;
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;
missing_feature_sample(0, avc, msg, argument_list);
va_end(argument_list);
}
+
+#ifdef TEST
+// LCOV_EXCL_START
+#include <string.h>
+
+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