aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/logging.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-08-26 11:43:54 +0200
committerGitHub Enterprise <[email protected]>2025-08-26 11:43:54 +0200
commitb734de7c3a36bc5ccef84c1c940e0e3208e96506 (patch)
tree75d3a936566987585b449c42ff867b9c9e5b404b /src/zencore/logging.cpp
parentrevert multi-cid store (#475) (diff)
downloadzen-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/logging.cpp')
-rw-r--r--src/zencore/logging.cpp23
1 files changed, 23 insertions, 0 deletions
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());
}