diff options
| author | Dan Engelbrecht <[email protected]> | 2025-08-26 11:43:54 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-08-26 11:43:54 +0200 |
| commit | b734de7c3a36bc5ccef84c1c940e0e3208e96506 (patch) | |
| tree | 75d3a936566987585b449c42ff867b9c9e5b404b /src/zencore | |
| parent | revert multi-cid store (#475) (diff) | |
| download | zen-b734de7c3a36bc5ccef84c1c940e0e3208e96506.tar.xz zen-b734de7c3a36bc5ccef84c1c940e0e3208e96506.zip | |
improve console output (#476)
* add color coded logging level to console output (for warn/err/crit levels)
* clean up console output
Diffstat (limited to 'src/zencore')
| -rw-r--r-- | src/zencore/include/zencore/logging.h | 1 | ||||
| -rw-r--r-- | src/zencore/logging.cpp | 23 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/zencore/include/zencore/logging.h b/src/zencore/include/zencore/logging.h index bffbe84b4..afbbbd3ee 100644 --- a/src/zencore/include/zencore/logging.h +++ b/src/zencore/include/zencore/logging.h @@ -59,7 +59,6 @@ struct LogCategory zen::LoggerRef LoggerRef; }; -void EmitConsoleLogMessage(int LogLevel, std::string_view Message); void EmitConsoleLogMessage(int LogLevel, std::string_view Format, fmt::format_args Args); void EmitLogMessage(LoggerRef& Logger, int LogLevel, std::string_view Message); void EmitLogMessage(LoggerRef& Logger, const SourceLocation& Location, int LogLevel, std::string_view Message); diff --git a/src/zencore/logging.cpp b/src/zencore/logging.cpp index 5885587ad..685c79d82 100644 --- a/src/zencore/logging.cpp +++ b/src/zencore/logging.cpp @@ -122,11 +122,34 @@ EmitConsoleLogMessage(int LogLevel, const std::string_view Message) ConsoleLog().SpdLogger->log(InLevel, Message); } +#define ZEN_COLOR_YELLOW "\033[0;33m" +#define ZEN_COLOR_RED "\033[0;31m" +#define ZEN_BRIGHT_COLOR_RED "\033[1;31m" +#define ZEN_COLOR_RESET "\033[0m" + void EmitConsoleLogMessage(int LogLevel, std::string_view Format, fmt::format_args Args) { ZEN_MEMSCOPE(ELLMTag::Logging); zen::logging::LoggingContext LogCtx; + + // We are not using a format option for console which include log level since it would interfere with normal console output + + const spdlog::level::level_enum InLevel = (spdlog::level::level_enum)LogLevel; + switch (InLevel) + { + case spdlog::level::level_enum::warn: + fmt::format_to(fmt::appender(LogCtx.MessageBuffer), ZEN_COLOR_YELLOW "Warning: " ZEN_COLOR_RESET); + break; + case spdlog::level::level_enum::err: + fmt::format_to(fmt::appender(LogCtx.MessageBuffer), ZEN_BRIGHT_COLOR_RED "Error: " ZEN_COLOR_RESET); + break; + case spdlog::level::level_enum::critical: + fmt::format_to(fmt::appender(LogCtx.MessageBuffer), ZEN_COLOR_RED "Critical: " ZEN_COLOR_RESET); + break; + default: + break; + } fmt::vformat_to(fmt::appender(LogCtx.MessageBuffer), Format, Args); zen::logging::EmitConsoleLogMessage(LogLevel, LogCtx.Message()); } |