aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/logging.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-04-13 12:09:05 +0200
committerGitHub Enterprise <[email protected]>2026-04-13 12:09:05 +0200
commite0879bed083eab09cfa28043a3b210714d0884b9 (patch)
tree00d5dddc9a046bd0112e1fddcfce430ced14a355 /src/zencore/logging.cpp
parentupdate minio (#947) (diff)
downloadzen-e0879bed083eab09cfa28043a3b210714d0884b9.tar.xz
zen-e0879bed083eab09cfa28043a3b210714d0884b9.zip
Logging and diagnostics improvements (#941)
Core logging and system diagnostics improvements, extracted from the compute branch. ### Logging - **Elapsed timestamps**: Console log now shows elapsed time since launch `[HH:MM:SS.mmm]` instead of full date/time; file logging is unchanged - **Short level names**: 3-letter short level names (`trc`/`dbg`/`inf`/`wrn`/`err`/`crt`) used by both console and file formatters via `ShortToStringView()` - **Consistent field order**: Standardized to `[timestamp] [level] [logger]` across both console and file formatters - **Slim LogMessage/LogPoint**: Remove redundant fields from `LogMessage` (derive level/source from `LogPoint`), flatten `LogPoint` to inline filename/line fields, shrink `LogLevel` to `int8_t` with `static_assert(sizeof(LogPoint) <= 32)` - **Remove default member initializers** and static default `LogPoint` from `LogMessage` — all fields initialized by constructor - **LoggerRef string constructor**: Convenience constructor accepting a string directly - **Fix SendMessage macro collision**: Replace `thread.h` include in `logmsg.h` with a forward declaration of `GetCurrentThreadId()` to avoid pulling in `windows.h` transitively ### System Diagnostics - **Cache static system metrics**: Add `RefreshDynamicSystemMetrics()` that only queries values that change at runtime (available memory, uptime, swap). `SystemMetricsTracker` snapshots full `GetSystemMetrics()` once at construction and reuses cached topology/total memory on each `Query()`, avoiding repeated `GetLogicalProcessorInformationEx` traversal on Windows, `/proc/cpuinfo` parsing on Linux, and `sysctl` topology calls on macOS
Diffstat (limited to 'src/zencore/logging.cpp')
-rw-r--r--src/zencore/logging.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/zencore/logging.cpp b/src/zencore/logging.cpp
index 5ada0cac7..ca34b7d0e 100644
--- a/src/zencore/logging.cpp
+++ b/src/zencore/logging.cpp
@@ -112,6 +112,14 @@ constinit std::string_view LevelNames[] = {std::string_view("trace", 5),
std::string_view("critical", 8),
std::string_view("off", 3)};
+constinit std::string_view ShortNames[] = {std::string_view("trc", 3),
+ std::string_view("dbg", 3),
+ std::string_view("inf", 3),
+ std::string_view("wrn", 3),
+ std::string_view("err", 3),
+ std::string_view("crt", 3),
+ std::string_view("off", 3)};
+
LogLevel
ParseLogLevelString(std::string_view Name)
{
@@ -139,12 +147,27 @@ ParseLogLevelString(std::string_view Name)
std::string_view
ToStringView(LogLevel Level)
{
+ using namespace std::literals;
+
if (int(Level) < LogLevelCount)
{
return LevelNames[int(Level)];
}
- return "None";
+ return "None"sv;
+}
+
+std::string_view
+ShortToStringView(LogLevel Level)
+{
+ using namespace std::literals;
+
+ if (int(Level) < LogLevelCount)
+ {
+ return ShortNames[int(Level)];
+ }
+
+ return "None"sv;
}
} // namespace zen::logging
@@ -476,6 +499,10 @@ LoggerRef::LoggerRef(logging::Logger& InLogger) : m_Logger(static_cast<logging::
{
}
+LoggerRef::LoggerRef(std::string_view LogCategory) : m_Logger(zen::logging::Get(LogCategory).m_Logger)
+{
+}
+
void
LoggerRef::Flush()
{