aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-09-21 15:25:24 +0200
committerGitHub <[email protected]>2022-09-21 06:25:24 -0700
commitc2f09732b0e180e8103e026e85b181733b918766 (patch)
tree269da49606d05f9245cb8299ecd9d0b186e7c617 /zencore/include
parenteditorconfig: our lua files use spaces for indentation (diff)
downloadzen-c2f09732b0e180e8103e026e85b181733b918766.tar.xz
zen-c2f09732b0e180e8103e026e85b181733b918766.zip
logging - don't do formatting of messages the will not be logged (#169)
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/logging.h112
1 files changed, 40 insertions, 72 deletions
diff --git a/zencore/include/zencore/logging.h b/zencore/include/zencore/logging.h
index 45dbd8c56..8c36c69f0 100644
--- a/zencore/include/zencore/logging.h
+++ b/zencore/include/zencore/logging.h
@@ -51,97 +51,65 @@ struct LogCategory
std::string Category;
};
+#define ZEN_LOG_WITH_LOCATION(logger, loc, level, fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ if (logger.should_log(level)) \
+ { \
+ logger.log(loc, level, fmtstr, ##__VA_ARGS__); \
+ } \
+ } while (false);
+
+#define ZEN_LOG(logger, level, fmtstr, ...) ZEN_LOG_WITH_LOCATION(logger, spdlog::source_loc{}, level, fmtstr, ##__VA_ARGS__)
+
#define ZEN_DEFINE_LOG_CATEGORY_STATIC(Category, Name) \
static struct LogCategory##Category : public LogCategory \
{ \
LogCategory##Category() : LogCategory(Name) {} \
} Category;
-#define ZEN_LOG_TRACE(Category, fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Category.Logger().trace(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_LOG_TRACE(Category, fmtstr, ...) ZEN_LOG(Category.Logger(), spdlog::level::trace, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_LOG_DEBUG(Category, fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Category.Logger().debug(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_LOG_DEBUG(Category, fmtstr, ...) ZEN_LOG(Category.Logger(), spdlog::level::debug, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_LOG_INFO(Category, fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Category.Logger().info(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_LOG_INFO(Category, fmtstr, ...) ZEN_LOG(Category.Logger(), spdlog::level::info, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_LOG_WARN(Category, fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Category.Logger().warn(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_LOG_WARN(Category, fmtstr, ...) ZEN_LOG(Category.Logger(), spdlog::level::warn, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_LOG_ERROR(Category, fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Category.Logger().error(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_LOG_ERROR(Category, fmtstr, ...) \
+ ZEN_LOG_WITH_LOCATION(Category.Logger(), \
+ spdlog::source_loc(__FILE__, __LINE__, SPDLOG_FUNCTION), \
+ spdlog::level::err, \
+ fmtstr##sv, \
+ ##__VA_ARGS__)
-#define ZEN_LOG_CRITICAL(Category, fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Category.Logger().critical(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_LOG_CRITICAL(Category, fmtstr, ...) \
+ ZEN_LOG_WITH_LOCATION(Category.Logger(), \
+ spdlog::source_loc(__FILE__, __LINE__, SPDLOG_FUNCTION), \
+ spdlog::level::critical, \
+ fmtstr##sv, \
+ ##__VA_ARGS__)
// Helper macros for logging
-#define ZEN_TRACE(fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Log().trace(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_TRACE(fmtstr, ...) ZEN_LOG(Log(), spdlog::level::trace, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_DEBUG(fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Log().debug(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_DEBUG(fmtstr, ...) ZEN_LOG(Log(), spdlog::level::debug, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_INFO(fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Log().info(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_INFO(fmtstr, ...) ZEN_LOG(Log(), spdlog::level::info, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_WARN(fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Log().warn(fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_WARN(fmtstr, ...) ZEN_LOG(Log(), spdlog::level::warn, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_ERROR(fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Log().log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, spdlog::level::err, fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_ERROR(fmtstr, ...) \
+ ZEN_LOG_WITH_LOCATION(Log(), spdlog::source_loc(__FILE__, __LINE__, SPDLOG_FUNCTION), spdlog::level::err, fmtstr##sv, ##__VA_ARGS__)
-#define ZEN_CRITICAL(fmtstr, ...) \
- do \
- { \
- using namespace std::literals; \
- Log().log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, spdlog::level::critical, fmtstr##sv, ##__VA_ARGS__); \
- } while (false)
+#define ZEN_CRITICAL(fmtstr, ...) \
+ ZEN_LOG_WITH_LOCATION(Log(), \
+ spdlog::source_loc(__FILE__, __LINE__, SPDLOG_FUNCTION), \
+ spdlog::level::critical, \
+ fmtstr##sv, \
+ ##__VA_ARGS__)
#define ZEN_CONSOLE(fmtstr, ...) \
do \