diff options
Diffstat (limited to 'src/common/log.h')
-rw-r--r-- | src/common/log.h | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/src/common/log.h b/src/common/log.h index bff4ab71b9..596bb1d991 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -50,7 +50,15 @@ #define LOG_ERR 3 #endif -typedef void (*log_callback)(int severity, const char *msg); +/* Logging domains */ +#define LD_GENERAL 0 +#define LD_CRYPTO 1 +#define LD_NET 2 +#define LD_CONFIG 3 +#define LD_FS 4 +#define LD_PROTOCOL 5 + +typedef void (*log_callback)(int severity, int domain, const char *msg); int parse_log_level(const char *level); const char *log_level_to_string(int level); @@ -73,29 +81,69 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax, log_callback cb); /* Outputs a message to stdout */ -void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3); +void _log(int severity, int domain, const char *format, ...) CHECK_PRINTF(3,4); #ifdef __GNUC__ -void _log_fn(int severity, const char *funcname, const char *format, ...) - CHECK_PRINTF(3,4); +void _log_fn(int severity, int domain, + const char *funcname, const char *format, ...) + CHECK_PRINTF(4,5); /** Log a message at level <b>severity</b>, using a pretty-printed version * of the current function name. */ -#define log_fn(severity, args...) \ - _log_fn(severity, __PRETTY_FUNCTION__, args) -#elif defined(_MSC_VER) && _MSC_VER < 1300 +#ifdef OLD_LOG_INTERFACE +#define log_fn(severity, args...) \ + _log_fn(severity, LD_GENERAL, __PRETTY_FUNCTION__, args) +#define log(severity, args...) \ + _log(severity, LD_GENERAL, args) +#else +#define log_fn(severity, domain, args...) \ + _log_fn(severity, domain, __PRETTY_FUNCTION__, args) +#define log _log +#endif +#define debug(domain, args...) \ + _log_fn(LOG_DEBUG, domain, __PRETTY_FUNCTION__, args) +#define info(domain, args...) \ + _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args) +#define notice(domain, args...) \ + _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args) +#define warn(domain, args...) \ + _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args) +#define err(args...) \ + _log_fn(LOG_ERR, LD_GENERAL, __PRETTY_FUNCTION__, args) +#else + +void _log_fn(int severity, int domain, const char *format, ...); +void _debug(int domain, const char *format, ...); +void _info(int domain, const char *format, ...); +void _notice(int domain, const char *format, ...); +void _warn(int domain, const char *format, ...); +void _err(const char *format, ...); + +#define log _log /* hack it so we don't conflict with log() as much */ + +#if defined(_MSC_VER) && _MSC_VER < 1300 /* MSVC 6 and earlier don't have __FUNCTION__, or even __LINE__. */ -#define log_fn _log +#define log_fn _log_fn +#define debug _debug +#define info _info +#define notice _notice +#define warn _warn +#define err _err #else /* We don't have GCC's varargs macros, so use a global variable to pass the * function name to log_fn */ extern const char *_log_fn_function_name; -void _log_fn(int severity, const char *format, ...); /* We abuse the comma operator here, since we can't use the standard * do {...} while (0) trick to wrap this macro, since the macro can't take * arguments. */ #define log_fn (_log_fn_function_name=__FUNCTION__),_log_fn +#define debug (_log_fn_function_name=__FUNCTION__),_debug +#define info (_log_fn_function_name=__FUNCTION__),_info +#define notice (_log_fn_function_name=__FUNCTION__),_notice +#define warn (_log_fn_function_name=__FUNCTION__),_warn +#define err (_log_fn_function_name=__FUNCTION__),_err #endif -#define log _log /* hack it so we don't conflict with log() as much */ + +#endif /* !GNUC */ # define __LOG_H #endif |