From 678a4619044a0f9f8decfeddd555e7b2d7084a0c Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 1 Aug 2023 20:23:05 +1000 Subject: Logger: Do string formatting before lock and only if LogLevel is loggable --- source/core/StarLogging.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source/core/StarLogging.hpp') diff --git a/source/core/StarLogging.hpp b/source/core/StarLogging.hpp index 3e71aff..1ab21a9 100644 --- a/source/core/StarLogging.hpp +++ b/source/core/StarLogging.hpp @@ -81,9 +81,13 @@ public: template static void error(char const* msg, Args const&... args); + static bool loggable(LogLevel level); + static void refreshLoggable(); private: + static shared_ptr s_stdoutSink; static HashSet s_sinks; + static Array s_loggable; static Mutex s_mutex; }; @@ -152,13 +156,13 @@ private: template void Logger::logf(LogLevel level, char const* msg, Args const&... args) { - MutexLocker locker(s_mutex); - Maybe output; - for (auto const& l : s_sinks) { - if (l->level() <= level) { - if (!output) - output = strf(msg, args...); - l->log(output->c_str(), level); + if (loggable(level)) { + std::string output = strf(msg, args...); + MutexLocker locker(s_mutex); + for (auto const& l : s_sinks) { + if (l->level() <= level) { + l->log(output.c_str(), level); + } } } } -- cgit v1.2.3