Include filename explicitly in logging APIs

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@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-09-27 14:28:44 +01:00
parent 96a1be95ef
commit 0225c566f4
7 changed files with 55 additions and 42 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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,
int 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,
int 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,
int 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,
int 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);
}
@ -875,8 +882,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,
int linenr ATTRIBUTE_UNUSED,
const char *funcname ATTRIBUTE_UNUSED,
const char *timestamp,
unsigned int flags,
const char *rawstr ATTRIBUTE_UNUSED,
@ -960,8 +968,9 @@ virLogPrioritySyslog(virLogPriority priority)
static void
virLogOutputToSyslog(const char *category ATTRIBUTE_UNUSED,
virLogPriority priority,
const char *funcname ATTRIBUTE_UNUSED,
const char *filename ATTRIBUTE_UNUSED,
int linenr ATTRIBUTE_UNUSED,
const char *funcname ATTRIBUTE_UNUSED,
const char *timestamp ATTRIBUTE_UNUSED,
unsigned int flags,
const char *rawstr ATTRIBUTE_UNUSED,

View File

@ -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,
int 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,
int 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,
int 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

View File

@ -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);
}

View File

@ -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);

View File

@ -482,8 +482,9 @@ static struct virtTestLogData testLog = { VIR_BUFFER_INITIALIZER };
static void
virtTestLogOutput(const char *category ATTRIBUTE_UNUSED,
virLogPriority priority ATTRIBUTE_UNUSED,
const char *filename ATTRIBUTE_UNUSED,
int lineno ATTRIBUTE_UNUSED,
const char *funcname ATTRIBUTE_UNUSED,
int linenr ATTRIBUTE_UNUSED,
const char *timestamp,
unsigned int flags,
const char *rawstr ATTRIBUTE_UNUSED,