color logs
authorMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 27 Mar 2025 13:03:50 +0000 (14:03 +0100)
committerMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 27 Mar 2025 13:03:50 +0000 (14:03 +0100)
makefile
verbose.h

index 7db77be21ed19d91867c391f63013b089b231e5b..d9f32256416cb086a5a1672c04228fc162eac396 100644 (file)
--- a/makefile
+++ b/makefile
@@ -3,7 +3,7 @@
 CC = gcc
 
 #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
-INCLUDES =
+INCLUDES += -DVERBOSE_COLOR=1
 OFLAGS  = -O4 -Os
 #OFLAGS  = -O0
 #OFLAGS  = -O4 -ffast-math -finline-functions
index 539f0858f5c91ee3ddc631b6faaba25f2d0475ca..2965ef339cfb253c231c04d0b8b2bf5bb408146e 100644 (file)
--- a/verbose.h
+++ b/verbose.h
 
 __BEGIN_DECLS
 
+#ifndef VERBOSE_COLOR
+#define VERBOSE_COLOR 0
+#endif
+
 /**
    Debug level
      - Error messages
@@ -69,7 +73,18 @@ __BEGIN_DECLS
         extern int verbose_##module;         \
         if (level > verbose_##module)        \
             break;                           \
+        if (VERBOSE_COLOR) {                 \
+            if (level == ERROR)              \
+                printf ("\e[1;31m");         \
+            else if (level == WARNING)       \
+                printf ("\e[1;33m");         \
+            else if (level == DEBUG)         \
+                printf ("\e[1;32m");         \
+            else if (level == TRACE)         \
+                printf ("\e[1;34m");         \
+        }                                    \
         statement;                           \
+        printf ("\e[0;0m");                  \
     } while(0)
 
 /**
@@ -80,7 +95,7 @@ __BEGIN_DECLS
 */
 #define PRINTF(format...)                        \
     do {                                         \
-        printf ("%s[%d]: ", __FILE__, __LINE__); \
+        printf ("%s+%d: ", __FILE__, __LINE__); \
         printf (format);                         \
         fflush (stdout);                         \
     } while (0)