diff options
| author | Dan Engelbrecht <[email protected]> | 2023-04-25 14:50:29 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-25 14:50:29 +0200 |
| commit | 0d0697cbe19ed2ef385408f72d754cea99c7bc9a (patch) | |
| tree | 9d05fec6bf2356b56fa432e3e97946adacfc9466 /zencore/include | |
| parent | 0.2.5 (diff) | |
| download | zen-0d0697cbe19ed2ef385408f72d754cea99c7bc9a.tar.xz zen-0d0697cbe19ed2ef385408f72d754cea99c7bc9a.zip | |
fix sentry report callstack (#256)
* Include file, line and function in sentry log error messages
* use sync direct error logger to get correct call stacks on error
* changelog
* use d1trimfile on windows to shorten file path on windows
* constexpr -> consteval
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/logging.h | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/zencore/include/zencore/logging.h b/zencore/include/zencore/logging.h index 8c36c69f0..44e3d40d4 100644 --- a/zencore/include/zencore/logging.h +++ b/zencore/include/zencore/logging.h @@ -17,6 +17,8 @@ spdlog::logger& Default(); void SetDefault(std::shared_ptr<spdlog::logger> NewDefaultLogger); spdlog::logger& ConsoleLog(); spdlog::logger& Get(std::string_view Name); +spdlog::logger* ErrorLog(); +void SetErrorLog(std::shared_ptr<spdlog::logger>&& NewErrorLogger); void InitializeLogging(); void ShutdownLogging(); @@ -33,9 +35,11 @@ Log() } using logging::ConsoleLog; +using logging::ErrorLog; } // namespace zen using zen::ConsoleLog; +using zen::ErrorLog; using zen::Log; struct LogCategory @@ -51,14 +55,27 @@ 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__); \ - } \ +inline consteval bool +LogIsErrorLevel(int level) +{ + return (level == spdlog::level::err || level == spdlog::level::critical); +}; + +#define ZEN_LOG_WITH_LOCATION(logger, loc, level, fmtstr, ...) \ + do \ + { \ + using namespace std::literals; \ + if (logger.should_log(level)) \ + { \ + if (LogIsErrorLevel(level)) \ + { \ + if (auto ErrLogger = zen::logging::ErrorLog(); ErrLogger != nullptr) \ + { \ + ErrLogger->log(loc, level, fmtstr, ##__VA_ARGS__); \ + } \ + } \ + 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__) @@ -91,7 +108,7 @@ struct LogCategory fmtstr##sv, \ ##__VA_ARGS__) -// Helper macros for logging + // Helper macros for logging #define ZEN_TRACE(fmtstr, ...) ZEN_LOG(Log(), spdlog::level::trace, fmtstr##sv, ##__VA_ARGS__) |