mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 10:29:02 +08:00
New compile time API using SPDLOG_ACTIVE_LEVEL
This commit is contained in:
@@ -290,36 +290,54 @@ inline void critical(const wchar_t *fmt, const Args &... args)
|
||||
|
||||
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
|
||||
//
|
||||
// Trace & Debug can be switched on/off at compile time with zero cost.
|
||||
// Uncomment SPDLOG_DEBUG_ON/SPDLOG_TRACE_ON in tweakme.h to enable.
|
||||
// SPDLOG_TRACE(..) will also print current file and line.
|
||||
//
|
||||
// Example:
|
||||
// spdlog::set_level(spdlog::level::trace);
|
||||
// SPDLOG_TRACE(my_logger, "another trace message {} {}", 1, 2);
|
||||
//
|
||||
// compile time level. defaults to info
|
||||
|
||||
#ifdef SPDLOG_TRACE_ON
|
||||
#define SPDLOG_STR_H(x) #x
|
||||
#define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x)
|
||||
#ifdef _MSC_VER
|
||||
#define SPDLOG_TRACE(logger, ...) \
|
||||
logger->trace("[ "__FILE__ \
|
||||
"(" SPDLOG_STR_HELPER(__LINE__) ")] " __VA_ARGS__)
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
|
||||
#define SPDLOG_LOGGER_TRACE(logger, ...) logger->trace(__VA_ARGS__)
|
||||
#define SPDLOG_TRACE(...) spdlog::trace(__VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_TRACE(logger, ...) \
|
||||
logger->trace("[" __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) "]" \
|
||||
" " __VA_ARGS__)
|
||||
#endif
|
||||
#else
|
||||
#define SPDLOG_TRACE(logger, ...) (void)0
|
||||
#define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
|
||||
#define SPDLOG_TRACE(...) (void)0
|
||||
#endif
|
||||
|
||||
#ifdef SPDLOG_DEBUG_ON
|
||||
#define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__)
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
|
||||
#define SPDLOG_LOGGER_DEBUG(logger, ...) logger->debug(__VA_ARGS__)
|
||||
#define SPDLOG_DEBUG(...) spdlog::debug(__VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_DEBUG(logger, ...) (void)0
|
||||
#define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
|
||||
#define SPDLOG_DEBUG(...) (void)0
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
|
||||
#define SPDLOG_LOGGER_INFO(logger, ...) logger->info(__VA_ARGS__)
|
||||
#define SPDLOG_INFO(...) spdlog::info(__VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_INFO(logger, ...) (void)0
|
||||
#define SPDLOG_INFO(...) (void)0
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
|
||||
#define SPDLOG_LOGGER_WARN(logger, ...) logger->warn(__VA_ARGS__)
|
||||
#define SPDLOG_WARN(...) spdlog::warn(__VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_WARN(logger, ...) (void)0
|
||||
#define SPDLOG_WARN(...) (void)0
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
|
||||
#define SPDLOG_LOGGER_ERROR(logger, ...) logger->error(__VA_ARGS__)
|
||||
#define SPDLOG_ERROR(...) spdlog::error(__VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
|
||||
#define SPDLOG_ERROR(...) (void)0
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
|
||||
#define SPDLOG_LOGGER_CRITICAL(logger, ...) logger->critical(__VA_ARGS__)
|
||||
#define SPDLOG_CRITICAL(...) spdlog::critical(__VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
|
||||
#define SPDLOG_CRITICAL(...) (void)0
|
||||
#endif
|
||||
|
||||
} // namespace spdlog
|
||||
|
Reference in New Issue
Block a user