diff --git a/SilKit/source/services/logging/ILoggerInternal.hpp b/SilKit/source/services/logging/ILoggerInternal.hpp index 541285647..1ca18b83f 100644 --- a/SilKit/source/services/logging/ILoggerInternal.hpp +++ b/SilKit/source/services/logging/ILoggerInternal.hpp @@ -82,18 +82,38 @@ class LoggerMessage template void FormatMessage(fmt::format_string fmt, Args&&... args) { - _msg = fmt::format(fmt, args...); + if (_logger->GetLogLevel() <= _level) + { + _msg = fmt::format(fmt, std::forward(args)...); + } } void SetMessage(std::string newMsg) { - _msg = std::move(newMsg); + if (_logger->GetLogLevel() <= _level) + { + _msg = std::move(newMsg); + } + } + + + template + void FormatKeyValue(Key&& key, fmt::format_string fmt, Args&&... args) + { + if (_logger->GetLogLevel() <= _level) + { + auto&& formattedValue = fmt::format(fmt, std::forward(args)...); + _keyValues.emplace_back(std::forward(key), formattedValue); + } } - template + template void SetKeyValue(Key&& key, Value&& value) { - _keyValues.push_back({std::forward(key), std::forward(value)}); + if (_logger->GetLogLevel() <= _level) + { + _keyValues.emplace_back(std::forward(key), std::forward(value)); + } } auto GetLevel() const -> Level diff --git a/SilKit/source/services/logging/MessageTracing.hpp b/SilKit/source/services/logging/MessageTracing.hpp index 4c4ff630a..7038f5ab9 100644 --- a/SilKit/source/services/logging/MessageTracing.hpp +++ b/SilKit/source/services/logging/MessageTracing.hpp @@ -58,15 +58,15 @@ void TraceRx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* add for (const auto& pair : addr->GetServiceDescriptor().to_keyValues()) { - lm.SetKeyValue(pair.first, pair.second); + lm.FormatKeyValue(pair.first, pair.second); } - lm.SetKeyValue(Logging::Keys::from, from.GetParticipantName()); - lm.SetKeyValue(Logging::Keys::msg, (fmt::format("{}", msg))); + lm.FormatKeyValue(Logging::Keys::from, from.GetParticipantName()); + lm.FormatKeyValue(Logging::Keys::msg, "{}", msg); auto virtualTimeStamp = GetTimestamp(msg); if (virtualTimeStamp != std::chrono::nanoseconds::duration::min()) { - lm.SetKeyValue(Logging::Keys::virtualTimeNS, (fmt::format("{}", virtualTimeStamp.count()))); + lm.FormatKeyValue(Logging::Keys::virtualTimeNS, "{}", virtualTimeStamp.count()); } lm.Dispatch(); @@ -80,15 +80,15 @@ void TraceTx(Logging::ILoggerInternal* logger, const Core::IServiceEndpoint* add for (const auto& pair : addr->GetServiceDescriptor().to_keyValues()) { - lm.SetKeyValue(pair.first, pair.second); + lm.FormatKeyValue(pair.first, pair.second); } - lm.SetKeyValue(Logging::Keys::msg, (fmt::format("{}", msg))); + lm.FormatKeyValue(Logging::Keys::msg, "{}", msg); auto virtualTimeStamp = GetTimestamp(msg); if (virtualTimeStamp != std::chrono::nanoseconds::duration::min()) { - lm.SetKeyValue(Logging::Keys::virtualTimeNS, (fmt::format("{}", virtualTimeStamp.count()))); + lm.FormatKeyValue(Logging::Keys::virtualTimeNS, "{}", virtualTimeStamp.count()); } lm.Dispatch(); }