diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-08-01 20:23:05 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-08-01 20:23:05 +1000 |
commit | 678a4619044a0f9f8decfeddd555e7b2d7084a0c (patch) | |
tree | 4bb3922f0dbe689453f01d6bdd0f4baf8fe1cae5 /source/core/StarLogging.hpp | |
parent | 9ba734ea14c610f54521f2faa30f048f0e4eadf9 (diff) |
Logger: Do string formatting before lock and only if LogLevel is loggable
Diffstat (limited to 'source/core/StarLogging.hpp')
-rw-r--r-- | source/core/StarLogging.hpp | 18 |
1 files changed, 11 insertions, 7 deletions
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 <typename... Args> static void error(char const* msg, Args const&... args); + static bool loggable(LogLevel level); + static void refreshLoggable(); private: + static shared_ptr<StdoutLogSink> s_stdoutSink; static HashSet<LogSinkPtr> s_sinks; + static Array<bool, 4> s_loggable; static Mutex s_mutex; }; @@ -152,13 +156,13 @@ private: template <typename... Args> void Logger::logf(LogLevel level, char const* msg, Args const&... args) { - MutexLocker locker(s_mutex); - Maybe<std::string> 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); + } } } } |