From 4c0406a69c05ff39eebaa075a795c1bbfc80f8de Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 23 Oct 2015 13:32:42 +0300 Subject: [PATCH] New logging macros This commit is only to introduce new logging macros. The current implementation is such that a statement like: MAXSCALE_NOTICE("Refreshing configuration following SIGHUP\n"); is equivalent with LOGIF(LM, (skygw_log_write( LOGFILE_MESSAGE, "Refreshing configuration following SIGHUP\n"))); The actual implementation will later be changed as the logging mechanism itself is changed. The names of the macros are now according to the levels of syslog and currently the mapping is like: MAXSCALE_ERROR (Syslog LOG_ERR) -> LOGFILE_ERROR MAXSCALE_WARNING (Syslog LOG_WARNING) -> LOGFILE_ERROR MAXSCALE_NOTICE (Syslof LOG_NOTICE) -> LOGFILE_MESSAGE MAXSCALE_INFO (Syslog LOG_INFO) -> LOGFILE_TRACE MAXSCALE_DEBUG (Syslog LOG_DEBUG) -> LOGFILE_DEBUG When log manager is changed to deal "natively" with syslog levels this mapping will disappear of course. --- log_manager/log_manager.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index a85736b85..8956b3cf0 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -182,4 +182,28 @@ const char* get_err_prefix_default(void); const char* get_err_suffix_default(void); const char* get_logpath_default(void); +/** + * Helper, not to be called directly. + */ +#define MAXSCALE_MESSAGE_FLUSH(id, format, ...)\ + do { if (LOG_IS_ENABLED(id)) { skygw_log_write_flush(id, format, ##__VA_ARGS__); } } while (false) + +/** + * Helper, not to be called directly. + */ +#define MAXSCALE_MESSAGE(id, format, ...)\ + do { if (LOG_IS_ENABLED(id)) { skygw_log_write(id, format, ##__VA_ARGS__); } } while (false) + +/** + * Log an error, warning, notice, info, or debug message. + * + * @param format The printf format of the message. + * @param ... Arguments, depending on the format. + */ +#define MAXSCALE_ERROR(format, ...) MAXSCALE_MESSAGE_FLUSH(LOGFILE_ERROR, format, ##__VA_ARGS__) +#define MAXSCALE_WARNING(format, ...) MAXSCALE_MESSAGE(LOGFILE_ERROR, format, ##__VA_ARGS__) +#define MAXSCALE_NOTICE(format, ...) MAXSCALE_MESSAGE(LOGFILE_MESSAGE, format, ##__VA_ARGS__) +#define MAXSCALE_INFO(format, ...) MAXSCALE_MESSAGE(LOGFILE_TRACE, format, ##__VA_ARGS__) +#define MAXSCALE_DEBUG(format, ...) MAXSCALE_MESSAGE(LOGFILE_DEBUG, format, ##__VA_ARGS__) + #endif /** LOG_MANAGER_H */