[FFmpeg-devel] [PATCH] add colours to warnings and errors

James Darnley james.darnley
Thu Apr 22 00:59:15 CEST 2010


Here is a patch which tries to prevent some pebkac issues.  It prints
AV_LOG_ERROR in red and AV_LOG_WARNING in yellow.

Index: libavutil/log.c
===================================================================
--- libavutil/log.c	(revision 22900)
+++ libavutil/log.c	(working copy)
@@ -24,6 +24,12 @@
  * logging functions
  */

+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
 #include "avutil.h"
 #include "log.h"

@@ -57,7 +63,37 @@
         fprintf(stderr, "    Last message repeated %d times\n", count);
         count=0;
     }
+
+#ifndef _WIN32
+#define SET_ERROR_COLOUR \
+    if (isatty(2)) \
+        fprintf( stderr, "\033[31;40m" );
+#define SET_WARNING_COLOUR \
+    if (isatty(2)) \
+        fprintf( stderr, "\033[33;40m" );
+#define RESET_COLOUR \
+    if (isatty(2)) \
+        fprintf( stderr, "\033[0m" );
+#else
+#define SET_ERROR_COLOUR \
+    SetConsoleTextAttribute(console, \
+        FOREGROUND_RED|FOREGROUND_INTENSITY);
+#define SET_WARNING_COLOUR \
+    SetConsoleTextAttribute(console, \
+        FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
+#define RESET_COLOUR \
+    SetConsoleTextAttribute(console, console_info.wAttributes);
+
+    HANDLE console = GetStdHandle(STD_ERROR_HANDLE);
+    CONSOLE_SCREEN_BUFFER_INFO console_info;
+    GetConsoleScreenBufferInfo(console, &console_info);
+#endif
+    if(level == AV_LOG_ERROR)
+        SET_ERROR_COLOUR
+    if(level == AV_LOG_WARNING)
+        SET_WARNING_COLOUR
     fputs(line, stderr);
+    RESET_COLOUR
     strcpy(prev, line);
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colours.diff
Type: application/octet-stream
Size: 1438 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100422/06cafab8/attachment.obj>



More information about the ffmpeg-devel mailing list