]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
* src/logging.h src/logging.c: commited the more recent version
authorDaniel Veillard <veillard@redhat.com>
Mon, 22 Dec 2008 10:44:10 +0000 (10:44 +0000)
committerDaniel Veillard <veillard@redhat.com>
Mon, 22 Dec 2008 10:44:10 +0000 (10:44 +0000)
  with function name and line number
daniel

ChangeLog
src/logging.c
src/logging.h

index 304a687d5fd5dfaf4cf9bca1f1ad94ca12e17bfc..c3dfcda43a9d1b0234b1484412d4e3d46916ad8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Dec 22 11:43:04 CET 2008 Daniel Veillard <veillard@redhat.com>
+
+       * src/logging.h src/logging.c: commited the more recent version
+         with function name and line number
+
 Mon Dec 22 11:33:07 CET 2008 Daniel Veillard <veillard@redhat.com>
 
        * src/logging.h src/logging.c: add the infrastructure and internal
index 27cd236e186eb61e96012b2cb3d97886a925e4c2..b1ff6dfb08eee63616eec0bc76f4586d5568e805 100644 (file)
@@ -469,6 +469,8 @@ cleanup:
  * virLogMessage:
  * @category: where is that message coming from
  * @priority: the priority level
+ * @funcname: the function emitting the (debug) message
+ * @linenr: line where the message was emitted
  * @flags: extra flags, 1 if coming from the error handler
  * @fmt: the string format
  * @...: the arguments
@@ -476,13 +478,13 @@ cleanup:
  * Call the libvirt logger with some informations. Based on the configuration
  * the message may be stored, sent to output or just discarded
  */
-void virLogMessage(const char *category, int priority, int flags,
-                   const char *fmt, ...) {
+void virLogMessage(const char *category, int priority, const char *funcname,
+                   long long linenr, int flags, const char *fmt, ...) {
     char *str = NULL;
     char *msg;
     struct timeval cur_time;
     struct tm time_info;
-    int len, fprio, i;
+    int len, fprio, i, ret;
 
     if (!virLogInitialized)
         virLogStartup();
@@ -509,15 +511,22 @@ void virLogMessage(const char *category, int priority, int flags,
     gettimeofday(&cur_time, NULL);
     localtime_r(&cur_time.tv_sec, &time_info);
 
-    if (asprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s\n",
-                 time_info.tm_hour, time_info.tm_min,
-                 time_info.tm_sec, (int) cur_time.tv_usec / 1000,
-                 virLogPriorityString(priority), str) < 0) {
+    if ((funcname != NULL) && (priority == VIR_LOG_DEBUG)) {
+        ret = asprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s:%lld : %s\n",
+                       time_info.tm_hour, time_info.tm_min,
+                       time_info.tm_sec, (int) cur_time.tv_usec / 1000,
+                       virLogPriorityString(priority), funcname, linenr, str);
+    } else {
+        ret = asprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s\n",
+                       time_info.tm_hour, time_info.tm_min,
+                       time_info.tm_sec, (int) cur_time.tv_usec / 1000,
+                       virLogPriorityString(priority), str);
+    }
+    VIR_FREE(str);
+    if (ret < 0) {
         /* apparently we're running out of memory */
-        VIR_FREE(str);
         return;
     }
-    VIR_FREE(str);
 
     /*
      * Log based on defaults, first store in the history buffer
@@ -532,8 +541,8 @@ void virLogMessage(const char *category, int priority, int flags,
     virLogLock();
     for (i = 0; i < virLogNbOutputs;i++) {
         if (priority >= virLogOutputs[i].priority)
-            virLogOutputs[i].f(virLogOutputs[i].data, category, priority,
-                               msg, len);
+            virLogOutputs[i].f(category, priority, funcname, linenr,
+                               msg, len, virLogOutputs[i].data);
     }
     if ((virLogNbOutputs == 0) && (flags != 1))
         safewrite(2, msg, len);
@@ -542,9 +551,11 @@ void virLogMessage(const char *category, int priority, int flags,
     VIR_FREE(msg);
 }
 
-static int virLogOutputToFd(void *data, const char *category ATTRIBUTE_UNUSED,
+static int virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
                             int priority ATTRIBUTE_UNUSED,
-                            const char *str, int len) {
+                            const char *funcname ATTRIBUTE_UNUSED,
+                            long long linenr ATTRIBUTE_UNUSED,
+                            const char *str, int len, void *data) {
     int fd = (long) data;
     int ret;
 
@@ -582,10 +593,12 @@ static int virLogAddOutputToFile(int priority, const char *file) {
 }
 
 #if HAVE_SYSLOG_H
-static int virLogOutputToSyslog(void *data ATTRIBUTE_UNUSED,
-                                const char *category ATTRIBUTE_UNUSED,
-                                int priority, const char *str,
-                                int len ATTRIBUTE_UNUSED) {
+static int virLogOutputToSyslog(const char *category ATTRIBUTE_UNUSED,
+                                int priority,
+                                const char *funcname ATTRIBUTE_UNUSED,
+                                long long linenr ATTRIBUTE_UNUSED,
+                                const char *str, int len ATTRIBUTE_UNUSED,
+                                void *data ATTRIBUTE_UNUSED) {
     int prio;
 
     switch (priority) {
index f6aab41eac40c93cb4d53db33e4e527479845039..84263702a81069891a72eeabf18b192658ca4b16 100644 (file)
  * defined at runtime of from the libvirt daemon configuration file
  */
 #ifdef ENABLE_DEBUG
-#define VIR_DEBUG(category, fmt,...)                                    \
-    virLogMessage(category, VIR_LOG_DEBUG, 0, fmt, __VA_ARGS__)
-#define VIR_INFO(category, fmt,...)                                    \
-    virLogMessage(category, VIR_LOG_INFO, 0, fmt, __VA_ARGS__)
-#define VIR_WARN(category, fmt,...)                                    \
-    virLogMessage(category, VIR_LOG_WARN, 0, fmt, __VA_ARGS__)
-#define VIR_ERROR(category, fmt,...)                                    \
-    virLogMessage(category, VIR_LOG_ERROR, 0, fmt, __VA_ARGS__)
+#define VIR_DEBUG(category, f, l, fmt,...)                             \
+    virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, fmt, __VA_ARGS__)
+#define VIR_INFO(category, f, l, fmt,...)                              \
+    virLogMessage(category, VIR_LOG_INFO, f, l, 0, fmt, __VA_ARGS__)
+#define VIR_WARN(category, f, l, fmt,...)                              \
+    virLogMessage(category, VIR_LOG_WARN, f, l, 0, fmt, __VA_ARGS__)
+#define VIR_ERROR(category, f, l, fmt,...)                             \
+    virLogMessage(category, VIR_LOG_ERROR, f, l, 0, fmt, __VA_ARGS__)
 #else
-#define VIR_DEBUG(category, fmt,...) \
+#define VIR_DEBUG(category, f, l, fmt,...) \
+    do { } while (0)
+#define VIR_INFO(category, f, l, fmt,...) \
+    do { } while (0)
+#define VIR_WARN(category, f, l, fmt,...) \
+    do { } while (0)
+#define VIR_ERROR(category, f, l, fmt,...) \
     do { } while (0)
 #define VIR_INFO(category, fmt,...) \
     do { } while (0)
     do { } while (0)
 #endif /* !ENABLE_DEBUG */
 
-#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
-#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
-#define INFO(fmt,...) VIR_INFO(__FILE__, fmt, __VA_ARGS__)
-#define INFO0(msg) VIR_INFO(__FILE__, "%s", msg)
-#define WARN(fmt,...) VIR_WARN(__FILE__, fmt, __VA_ARGS__)
-#define WARN0(msg) VIR_WARN(__FILE__, "%s", msg)
-#define ERROR(fmt,...) VIR_ERROR(__FILE__, fmt, __VA_ARGS__)
-#define ERROR0(msg) VIR_ERROR(__FILE__, "%s", msg)
+#define DEBUG(fmt,...)                                                  \
+        VIR_DEBUG("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
+#define DEBUG0(msg)                                                     \
+        VIR_DEBUG("file." __FILE__, __func__, __LINE__, "%s", msg)
+#define INFO(fmt,...)                                                   \
+        VIR_INFO("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
+#define INFO0(msg)                                                      \
+        VIR_INFO("file." __FILE__, __func__, __LINE__, "%s", msg)
+#define WARN(fmt,...)                                                   \
+        VIR_WARN("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
+#define WARN0(msg)                                                      \
+        VIR_WARN("file." __FILE__, __func__, __LINE__, "%s", msg)
+#define ERROR(fmt,...)                                                  \
+        VIR_ERROR("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
+#define ERROR0(msg)                                                     \
+        VIR_ERROR("file." __FILE__, __func__, __LINE__, "%s", msg)
 
 
 /*
@@ -71,18 +85,21 @@ typedef enum {
 
 /**
  * virLogOutputFunc:
- * @data: extra output logging data
  * @category: the category for the message
  * @priority: the priority for the message
+ * @funcname: the function emitting the message
+ * @linenr: line where the message was emitted
  * @msg: the message to log, preformatted and zero terminated
  * @len: the lenght of the message in bytes without the terminating zero
+ * @data: extra output logging data
  *
  * Callback function used to output messages
  *
  * Returns the number of bytes written or -1 in case of error
  */
-typedef int (*virLogOutputFunc) (void *data, const char *category,
-                                 int priority, const char *str, int len);
+typedef int (*virLogOutputFunc) (const char *category, int priority,
+                                 const char *funcname, long long lineno,
+                                 const char *str, int len, void *data);
 
 /**
  * virLogCloseFunc:
@@ -110,7 +127,8 @@ extern int virLogReset(void);
 extern void virLogShutdown(void);
 extern int virLogParseFilters(const char *filters);
 extern int virLogParseOutputs(const char *output);
-extern void virLogMessage(const char *category, int priority, int flags,
-                          const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 4, 5);
+extern void virLogMessage(const char *category, int priority,
+                          const char *funcname, long long linenr, int flags,
+                          const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 6, 7);
 
 #endif