Convert logging to use UC_SRC_LOCATION

This commit is contained in:
Nils O. Selåsdal
2013-10-16 01:44:36 +02:00
parent 13567e3cd9
commit ee3dd22b0e
2 changed files with 14 additions and 15 deletions
+7 -6
View File
@@ -1,5 +1,6 @@
#ifndef UC_LOGGING_H_ #ifndef UC_LOGGING_H_
#define UC_LOGGING_H_ #define UC_LOGGING_H_
#include "utils.h"
/** Logging functions. /** Logging functions.
* All logging functions except uc_log_init are thread safe, * All logging functions except uc_log_init are thread safe,
@@ -268,14 +269,14 @@ int uc_log_reopen_files(void);
void uc_log_init(struct uc_log_modules *user_modules); void uc_log_init(struct uc_log_modules *user_modules);
void uc_logf(int log_level, int module, int raw, void uc_logf(int log_level, int module, int raw,
const char *file, int line, const char *fmt, ...) const char *location, const char *fmt, ...)
__attribute__((format(printf, 6, 7))); __attribute__((format(printf, 5, 6)));
#ifdef DEBUG #ifdef DEBUG
# define UC_DEBUGF(mod, fmt, ...)\ # define UC_DEBUGF(mod, fmt, ...)\
uc_logf(UC_LL_DEBUG, mod,0 , __FILE__, __LINE__, fmt, ## __VA_ARGS__) uc_logf(UC_LL_DEBUG, mod,0 , UC_SRC_LOCATION fmt, ## __VA_ARGS__)
# define UC_DEBUGFR(mod, fmt, ...)\ # define UC_DEBUGFR(mod, fmt, ...)\
uc_logf(UC_LL_DEBUG, mod,1 , __FILE__, __LINE__, fmt, ## __VA_ARGS__) uc_logf(UC_LL_DEBUG, mod,1 , UC_SRC_LOCATION, fmt, ## __VA_ARGS__)
#else #else
# define UC_DEBUGF(mod, fmt, ...) # define UC_DEBUGF(mod, fmt, ...)
# define UC_DEBUGFR(mod, fmt, ...) # define UC_DEBUGFR(mod, fmt, ...)
@@ -292,14 +293,14 @@ void uc_logf(int log_level, int module, int raw,
* @param ... printf style arguments * @param ... printf style arguments
*/ */
#define UC_LOGF(lvl, mod, fmt, ...) \ #define UC_LOGF(lvl, mod, fmt, ...) \
uc_logf(lvl, mod, 0, __FILE__, __LINE__, fmt, ## __VA_ARGS__) uc_logf(lvl, mod, 0, UC_SRC_LOCATION, fmt, ## __VA_ARGS__)
/** Raw logging ,Like UC_LOGF, but only prints the supplied /** Raw logging ,Like UC_LOGF, but only prints the supplied
* data, not timestamp, log level etc. * data, not timestamp, log level etc.
*/ */
#define UC_LOGFR(lvl, mod, fmt, ...) \ #define UC_LOGFR(lvl, mod, fmt, ...) \
uc_logf(lvl, mod, 1, __FILE__, __LINE__, fmt, ## __VA_ARGS__) uc_logf(lvl, mod, 1, UC_SRC_LOCATION, fmt, ## __VA_ARGS__)
#ifdef __cplusplus #ifdef __cplusplus
} }
+7 -9
View File
@@ -42,8 +42,7 @@ struct uc_log_args {
struct uc_log_destination *dest; struct uc_log_destination *dest;
const struct uc_log_module *module; const struct uc_log_module *module;
int log_level; int log_level;
const char *file; const char *location;
int line;
int raw; int raw;
}; };
@@ -415,9 +414,9 @@ static inline void uc_vlog_file(const struct uc_log_args *args, const char *fmt,
time_buf[sizeof time_buf -1] = 0; time_buf[sizeof time_buf -1] = 0;
if (dest->log_location) { if (dest->log_location) {
fprintf(dest->type.file.file, "[%-7s] %s %s:%d [%s] : ", fprintf(dest->type.file.file, "[%-7s] %s %s [%s] : ",
uc_ll_2_str(args->log_level), time_buf, args->file, uc_ll_2_str(args->log_level), time_buf,
args->line, args->module->short_name); args->location, args->module->short_name);
} else { } else {
fprintf(dest->type.file.file, "[%-7s] %s [%s]: ", fprintf(dest->type.file.file, "[%-7s] %s [%s]: ",
uc_ll_2_str(args->log_level), time_buf, args->module->short_name); uc_ll_2_str(args->log_level), time_buf, args->module->short_name);
@@ -446,7 +445,7 @@ static inline void uc_vlog_syslog(const struct uc_log_args *args, const char *fm
buf[0] = 0; buf[0] = 0;
if (dest->log_location) { if (dest->log_location) {
rc = snprintf(buf, sizeof buf, "%s:%d ", args->file, args->line); rc = snprintf(buf, sizeof buf, "%s ", args->location);
if (rc < 0) if (rc < 0)
goto log; goto log;
offset += rc; offset += rc;
@@ -543,7 +542,7 @@ void uc_log_destination_set_mask(
} }
void uc_logf(int log_level, int module, int raw, void uc_logf(int log_level, int module, int raw,
const char *file, int line, const char *fmt, ...) const char *location, const char *fmt, ...)
{ {
va_list ap; va_list ap;
struct uc_log_destination *dest; struct uc_log_destination *dest;
@@ -581,8 +580,7 @@ void uc_logf(int log_level, int module, int raw,
.dest = dest, .dest = dest,
.module = log_module, .module = log_module,
.log_level = log_level, .log_level = log_level,
.file = file, .location = location,
.line = line,
.raw = raw .raw = raw
}; };