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