[PATCH 5/9] Include filename explicitly in logging APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Currently the logging APIs have a 'const char *category' parameter
which indicates where the log message comes from. This is typically
a combination of the __FILE__ string and other prefix. Split the
__FILE__ off into a dedicated parameter so it can passed to the
log outputs

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/internal.h                     |  8 ++++----
 src/node_device/node_device_udev.c |  2 +-
 src/util/logging.c                 | 35 ++++++++++++++++++++------------
 src/util/logging.h                 | 41 ++++++++++++++++++++------------------
 src/util/viraudit.c                |  4 ++--
 src/util/virterror.c               |  4 ++--
 tests/testutils.c                  |  5 +++--
 7 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/src/internal.h b/src/internal.h
index 8037a4a..a1d46b9 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -349,15 +349,15 @@
 
 #  define PROBE_EXPAND(NAME, ARGS) NAME(ARGS)
 #  define PROBE(NAME, FMT, ...)                              \
-    VIR_DEBUG_INT("trace." __FILE__ , __func__, __LINE__,    \
+    VIR_DEBUG_INT("trace", __FILE__ , __LINE__, __func__,    \
                   #NAME ": " FMT, __VA_ARGS__);              \
-    if (LIBVIRT_ ## NAME ## _ENABLED()) {                   \
-        PROBE_EXPAND(LIBVIRT_ ## NAME,                      \
+    if (LIBVIRT_ ## NAME ## _ENABLED()) {                    \
+        PROBE_EXPAND(LIBVIRT_ ## NAME,                       \
                      VIR_ADD_CASTS(__VA_ARGS__));            \
     }
 # else
 #  define PROBE(NAME, FMT, ...)                              \
-    VIR_DEBUG_INT("trace." __FILE__, __func__, __LINE__,     \
+    VIR_DEBUG_INT("trace", __FILE__, __LINE__, __func__,     \
                   #NAME ": " FMT, __VA_ARGS__);
 # endif
 
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index ba17010..2104bd3 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -358,7 +358,7 @@ static void udevLogFunction(struct udev *udev ATTRIBUTE_UNUSED,
                             const char *fmt,
                             va_list args)
 {
-    VIR_ERROR_INT(file, fn, line, fmt, args);
+    VIR_ERROR_INT("library", file, line, fn, fmt, args);
 }
 
 
diff --git a/src/util/logging.c b/src/util/logging.c
index 5b29646..ceab64d 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -100,8 +100,9 @@ static int virLogResetFilters(void);
 static int virLogResetOutputs(void);
 static void virLogOutputToFd(const char *category,
                              virLogPriority priority,
-                             const char *funcname,
+                             const char *filename,
                              size_t linenr,
+                             const char *funcname,
                              const char *timestamp,
                              unsigned int flags,
                              const char *rawstr,
@@ -651,8 +652,8 @@ cleanup:
 
 static int
 virLogFormatString(char **msg,
-                   const char *funcname,
                    size_t linenr,
+                   const char *funcname,
                    virLogPriority priority,
                    const char *str)
 {
@@ -696,7 +697,7 @@ virLogVersionString(const char **rawmsg,
 #endif
 
     *rawmsg = LOG_VERSION_STRING;
-    return virLogFormatString(msg, NULL, 0, VIR_LOG_INFO, LOG_VERSION_STRING);
+    return virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, LOG_VERSION_STRING);
 }
 
 
@@ -716,14 +717,17 @@ virLogVersionString(const char **rawmsg,
 void
 virLogMessage(const char *category,
               virLogPriority priority,
-              const char *funcname,
+              const char *filename,
               size_t linenr,
+              const char *funcname,
               unsigned int flags,
               const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    virLogVMessage(category, priority, funcname, linenr, flags, fmt, ap);
+    virLogVMessage(category, priority,
+                   filename, linenr, funcname,
+                   flags, fmt, ap);
     va_end(ap);
 }
 
@@ -744,8 +748,9 @@ virLogMessage(const char *category,
 void
 virLogVMessage(const char *category,
                virLogPriority priority,
-               const char *funcname,
+               const char *filename,
                size_t linenr,
+               const char *funcname,
                unsigned int flags,
                const char *fmt,
                va_list vargs)
@@ -786,7 +791,7 @@ virLogVMessage(const char *category,
         goto cleanup;
     }
 
-    ret = virLogFormatString(&msg, funcname, linenr, priority, str);
+    ret = virLogFormatString(&msg, linenr, funcname, priority, str);
     if (ret < 0)
         goto cleanup;
 
@@ -816,13 +821,14 @@ virLogVMessage(const char *category,
                 char *ver = NULL;
                 if (virLogVersionString(&rawver, &ver) >= 0)
                     virLogOutputs[i].f(category, VIR_LOG_INFO,
-                                       __func__, __LINE__,
+                                       __FILE__, __LINE__, __func__,
                                        timestamp, 0, rawver, ver,
                                        virLogOutputs[i].data);
                 VIR_FREE(ver);
                 virLogOutputs[i].logVersion = false;
             }
-            virLogOutputs[i].f(category, priority, funcname, linenr,
+            virLogOutputs[i].f(category, priority,
+                               filename, linenr, funcname,
                                timestamp, filterflags,
                                str, msg, virLogOutputs[i].data);
         }
@@ -833,13 +839,14 @@ virLogVMessage(const char *category,
             char *ver = NULL;
             if (virLogVersionString(&rawver, &ver) >= 0)
                 virLogOutputToFd(category, VIR_LOG_INFO,
-                                 __func__, __LINE__,
+                                 __FILE__, __LINE__, __func__,
                                  timestamp, 0, rawver, ver,
                                  (void *) STDERR_FILENO);
             VIR_FREE(ver);
             logVersionStderr = false;
         }
-        virLogOutputToFd(category, priority, funcname, linenr,
+        virLogOutputToFd(category, priority,
+                         filename, linenr, funcname,
                          timestamp, filterflags,
                          str, msg, (void *) STDERR_FILENO);
     }
@@ -876,8 +883,9 @@ virLogStackTraceToFd(int fd)
 static void
 virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
                  virLogPriority priority ATTRIBUTE_UNUSED,
-                 const char *funcname ATTRIBUTE_UNUSED,
+                 const char *filename ATTRIBUTE_UNUSED,
                  size_t linenr ATTRIBUTE_UNUSED,
+                 const char *funcname ATTRIBUTE_UNUSED,
                  const char *timestamp,
                  unsigned int flags,
                  const char *rawstr ATTRIBUTE_UNUSED,
@@ -961,8 +969,9 @@ virLogPrioritySyslog(virLogPriority priority)
 static void
 virLogOutputToSyslog(const char *category ATTRIBUTE_UNUSED,
                      virLogPriority priority,
-                     const char *funcname ATTRIBUTE_UNUSED,
+                     const char *filename ATTRIBUTE_UNUSED,
                      size_t linenr ATTRIBUTE_UNUSED,
+                     const char *funcname ATTRIBUTE_UNUSED,
                      const char *timestamp ATTRIBUTE_UNUSED,
                      unsigned int flags,
                      const char *rawstr ATTRIBUTE_UNUSED,
diff --git a/src/util/logging.h b/src/util/logging.h
index 6e1de5d..25e6a1c 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -31,8 +31,8 @@
  * defined at runtime from the libvirt daemon configuration file
  */
 # ifdef ENABLE_DEBUG
-#  define VIR_DEBUG_INT(category, f, l, ...)                            \
-    virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__)
+#  define VIR_DEBUG_INT(category, filename, linenr, funcname, ...)                            \
+    virLogMessage(category, VIR_LOG_DEBUG, filename, linenr, funcname, 0, __VA_ARGS__)
 # else
 /**
  * virLogEatParams:
@@ -44,25 +44,25 @@ static inline void virLogEatParams(const char *unused, ...)
     /* Silence gcc */
     unused = unused;
 }
-#  define VIR_DEBUG_INT(category, f, l, ...)    \
-    virLogEatParams(category, f, l, __VA_ARGS__)
+#  define VIR_DEBUG_INT(category, filename, linenr, funcname, ...)    \
+    virLogEatParams(category, filename, linenr, funcname, __VA_ARGS__)
 # endif /* !ENABLE_DEBUG */
 
-# define VIR_INFO_INT(category, f, l, ...)                              \
-    virLogMessage(category, VIR_LOG_INFO, f, l, 0, __VA_ARGS__)
-# define VIR_WARN_INT(category, f, l, ...)                              \
-    virLogMessage(category, VIR_LOG_WARN, f, l, 0, __VA_ARGS__)
-# define VIR_ERROR_INT(category, f, l, ...)                             \
-    virLogMessage(category, VIR_LOG_ERROR, f, l, 0, __VA_ARGS__)
+# define VIR_INFO_INT(category, filename, linenr, funcname, ...)                              \
+    virLogMessage(category, VIR_LOG_INFO, filename, linenr, funcname, 0, __VA_ARGS__)
+# define VIR_WARN_INT(category, filename, linenr, funcname, ...)                              \
+    virLogMessage(category, VIR_LOG_WARN, filename, linenr, funcname, 0, __VA_ARGS__)
+# define VIR_ERROR_INT(category, filename, linenr, funcname, ...)                             \
+    virLogMessage(category, VIR_LOG_ERROR, filename, linenr, funcname, 0, __VA_ARGS__)
 
 # define VIR_DEBUG(...)                                                 \
-        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
+        VIR_DEBUG_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
 # define VIR_INFO(...)                                                  \
-        VIR_INFO_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
+        VIR_INFO_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
 # define VIR_WARN(...)                                                  \
-        VIR_WARN_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
+        VIR_WARN_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
 # define VIR_ERROR(...)                                                 \
-        VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
+        VIR_ERROR_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
 
 /*
  * To be made public
@@ -98,8 +98,9 @@ typedef enum {
  */
 typedef void (*virLogOutputFunc) (const char *category,
                                   virLogPriority priority,
-                                  const char *funcname,
+                                  const char *filename,
                                   size_t linenr,
+                                  const char *funcname,
                                   const char *timestamp,
                                   unsigned int flags,
                                   const char *rawstr,
@@ -148,17 +149,19 @@ extern int virLogParseFilters(const char *filters);
 extern int virLogParseOutputs(const char *output);
 extern void virLogMessage(const char *category,
                           virLogPriority priority,
-                          const char *funcname,
+                          const char *filename,
                           size_t linenr,
+                          const char *funcname,
                           unsigned int flags,
-                          const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
+                          const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(7, 8);
 extern void virLogVMessage(const char *category,
                            virLogPriority priority,
-                           const char *funcname,
+                           const char *filename,
                            size_t linenr,
+                           const char *funcname,
                            unsigned int flags,
                            const char *fmt,
-                           va_list vargs) ATTRIBUTE_FMT_PRINTF(6, 0);
+                           va_list vargs) ATTRIBUTE_FMT_PRINTF(7, 0);
 extern int virLogSetBufferSize(int size);
 extern void virLogEmergencyDumpAll(int signum);
 #endif
diff --git a/src/util/viraudit.c b/src/util/viraudit.c
index 5941714..ea1a79b 100644
--- a/src/util/viraudit.c
+++ b/src/util/viraudit.c
@@ -103,10 +103,10 @@ void virAuditSend(const char *file ATTRIBUTE_UNUSED, const char *func,
 
     if (auditlog && str) {
         if (success)
-            virLogMessage("audit", VIR_LOG_INFO, func, linenr, 0,
+            virLogMessage("audit", VIR_LOG_INFO, file, linenr, func, 0,
                           "success=yes %s", str);
         else
-            virLogMessage("audit", VIR_LOG_WARN, func, linenr, 0,
+            virLogMessage("audit", VIR_LOG_WARN, file, linenr, func, 0,
                           "success=no %s", str);
     }
 
diff --git a/src/util/virterror.c b/src/util/virterror.c
index b257e25..53f80af 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -676,8 +676,8 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
     priority = virErrorLevelPriority(level);
     if (virErrorLogPriorityFilter)
         priority = virErrorLogPriorityFilter(to, priority);
-    virLogMessage(filename, priority,
-                  funcname, linenr,
+    virLogMessage("error", priority,
+                  filename, linenr, funcname,
                   virErrorLogPriorityFilter ? 0 : 1,
                   "%s", str);
 
diff --git a/tests/testutils.c b/tests/testutils.c
index a33b10d..244db43 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -481,9 +481,10 @@ static struct virtTestLogData testLog = { VIR_BUFFER_INITIALIZER };
 
 static void
 virtTestLogOutput(const char *category ATTRIBUTE_UNUSED,
-                  int priority ATTRIBUTE_UNUSED,
+                  virLogPriority priority ATTRIBUTE_UNUSED,
+                  const char *filename ATTRIBUTE_UNUSED,
+                  size_t lineno ATTRIBUTE_UNUSED,
                   const char *funcname ATTRIBUTE_UNUSED,
-                  long long lineno ATTRIBUTE_UNUSED,
                   const char *timestamp,
                   unsigned int flags,
                   const char *rawstr ATTRIBUTE_UNUSED,
-- 
1.7.11.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]