diff options
| author | Per Larsson <[email protected]> | 2022-02-15 14:01:27 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2022-02-15 14:01:27 +0100 |
| commit | 921ce02cca7c15113452fde59bafc8fb58663b98 (patch) | |
| tree | aa156785a389f0713a9999a68aaad25b851c634b /zencore/include | |
| parent | Initial websocket support. (diff) | |
| download | zen-921ce02cca7c15113452fde59bafc8fb58663b98.tar.xz zen-921ce02cca7c15113452fde59bafc8fb58663b98.zip | |
Refactored websocket server and added static logger support.
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/logging.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/zencore/include/zencore/logging.h b/zencore/include/zencore/logging.h index 468e5d6e2..74ab0f81f 100644 --- a/zencore/include/zencore/logging.h +++ b/zencore/include/zencore/logging.h @@ -38,6 +38,67 @@ using logging::ConsoleLog; using zen::ConsoleLog; using zen::Log; +struct LogCategory +{ + LogCategory(std::string_view InCategory) : Category(InCategory) {} + + spdlog::logger& Logger() + { + static spdlog::logger& Inst = zen::logging::Get(Category); + return Inst; + } + + std::string Category; +}; + +#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_DEBUG(Category, fmtstr, ...) \ + do \ + { \ + using namespace std::literals; \ + Category.Logger().debug(fmtstr##sv, ##__VA_ARGS__); \ + } while (false) + +#define ZEN_LOG_INFO(Category, fmtstr, ...) \ + do \ + { \ + using namespace std::literals; \ + Category.Logger().info(fmtstr##sv, ##__VA_ARGS__); \ + } while (false) + +#define ZEN_LOG_WARN(Category, fmtstr, ...) \ + do \ + { \ + using namespace std::literals; \ + Category.Logger().warn(fmtstr##sv, ##__VA_ARGS__); \ + } while (false) + +#define ZEN_LOG_ERROR(Category, fmtstr, ...) \ + do \ + { \ + using namespace std::literals; \ + Category.Logger().error(fmtstr##sv, ##__VA_ARGS__); \ + } while (false) + +#define ZEN_LOG_CRITICAL(Category, fmtstr, ...) \ + do \ + { \ + using namespace std::literals; \ + Category.Logger().critical(fmtstr##sv, ##__VA_ARGS__); \ + } while (false) + // Helper macros for logging #define ZEN_TRACE(fmtstr, ...) \ |