add level in logs
authorLaurent Mazet <mazet@softndesign.org>
Fri, 28 Mar 2025 06:34:54 +0000 (07:34 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 28 Mar 2025 06:34:54 +0000 (07:34 +0100)
morep.c
morep_server.c
verbose.h

diff --git a/morep.c b/morep.c
index 5506357e5fcee77233c2db9d9834716b8830a5e5..b5b27bf30875ce7e7b0178f99b4ed9e2416305b6 100644 (file)
--- a/morep.c
+++ b/morep.c
@@ -319,7 +319,7 @@ int MOREP_Connect (char *url)
 
     /* bind socket */
     if (bind (sock, (struct sockaddr *)&sock_addr, sizeof (sock_addr)) != 0) {
-        VERBOSE (morep, ERROR, printf ("can't bind '%s': %s\n", url, strerror (errno)));
+        VERBOSE (morep, ERROR, PRINTF ("can't bind '%s': %s\n", url, strerror (errno)));
         return -1;
     }
 
index 6d27d1a489dcf0ebf1e6d70784d0655d8e632f80..608a3e85e59f7c16b7330aa97329317833132d2e 100644 (file)
@@ -263,7 +263,7 @@ int main (int argc, char **argv)
         case 'f':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, fprintf (stderr, "%s: message file not specified\n", progname));
+                VERBOSE (morep, ERROR, PRINTF ("%s: message file not specified\n", progname));
                 return 1;
             }
             filename = arg;
@@ -274,7 +274,7 @@ int main (int argc, char **argv)
         case 's':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, fprintf (stderr, "%s: message type not specified\n", progname));
+                VERBOSE (morep, ERROR, PRINTF ("%s: message type not specified\n", progname));
                 return 1;
             }
             msgtype = atoi (arg);
@@ -282,7 +282,7 @@ int main (int argc, char **argv)
         case 'v':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, fprintf (stderr, "%s: verbose level not specified\n", progname));
+                VERBOSE (morep, ERROR, PRINTF ("%s: verbose level not specified\n", progname));
                 return 1;
             }
             CHANGE_VERBOSE_LEVEL (morep, atoi (arg));
index 614e0959a7427147e3ee7d9eae09f72022c21f39..4bdb4d2df03f6a03810e48fcfa88e30b66c3c084 100644 (file)
--- a/verbose.h
+++ b/verbose.h
@@ -68,24 +68,25 @@ __BEGIN_DECLS
    @param level verbose level
    @param statement controled statement
 */
-#define VERBOSE(module, level, statement...) \
-    do {                                     \
-        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;                           \
-        if (VERBOSE_COLOR)                   \
-            printf ("\e[0;0m");              \
+#define VERBOSE(module, level, statement...)            \
+    do {                                                \
+        char __attribute__ ((unused)) *_level = #level; \
+        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;                                      \
+        if (VERBOSE_COLOR)                              \
+            printf ("\e[0;0m");                         \
     } while(0)
 
 /**
@@ -94,11 +95,11 @@ __BEGIN_DECLS
    @param format format string
    @param ... optionnal arguments
 */
-#define PRINTF(format...)                        \
-    do {                                         \
-        printf ("%s+%d: ", __FILE__, __LINE__); \
-        printf (format);                         \
-        fflush (stdout);                         \
+#define PRINTF(format...)                                   \
+    do {                                                    \
+        printf ("%s+%d[%s]: ", __FILE__, __LINE__, _level); \
+        printf (format);                                    \
+        fflush (stdout);                                    \
     } while (0)
 
 
@@ -109,11 +110,11 @@ __BEGIN_DECLS
    @param format format string
    @param ... optionnal arguments
 */
-#define FPRINTF(stream, format...)                       \
-    do {                                                 \
-        fprintf (stream,"%s[%d]: ", __FILE__, __LINE__); \
-        fprintf (stream, format);                        \
-        fflush (stream);                                 \
+#define FPRINTF(stream, format...)                                  \
+    do {                                                            \
+        fprintf (stream,"%s+%d[%s]: ", __FILE__, __LINE__, _level); \
+        fprintf (stream, format);                                   \
+        fflush (stream);                                            \
     } while (0)
 
 __END_DECLS