* 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
* 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();
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
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);
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;
}
#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) {
* 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)
/*
/**
* 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:
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