From d26f9c2fb5a9666822a0f702d76b764600a390d7 Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 13 Oct 2023 22:04:12 +0100 Subject: Further CLI and modifier reading work --- src/openvic-simulation/utility/Logger.hpp | 33 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/openvic-simulation/utility/Logger.hpp') diff --git a/src/openvic-simulation/utility/Logger.hpp b/src/openvic-simulation/utility/Logger.hpp index 11cada5..d60e59e 100644 --- a/src/openvic-simulation/utility/Logger.hpp +++ b/src/openvic-simulation/utility/Logger.hpp @@ -32,7 +32,7 @@ namespace OpenVic { }; #endif - class Logger { + class Logger final { using log_func_t = std::function; using log_queue_t = std::queue; @@ -42,39 +42,46 @@ namespace OpenVic { using source_location = OpenVic::source_location; #endif - static char const* get_filename(char const* filepath); + public: + static void set_logger_funcs(); + static char const* get_filename(char const* filepath, char const* default_path = nullptr); + + private: + struct log_channel_t { + log_func_t func; + log_queue_t queue; + }; template struct log { - log(log_func_t log_func, log_queue_t& log_queue, Ts&&... ts, source_location const& location) { + log(log_channel_t& log_channel, Ts&&... ts, source_location const& location) { std::stringstream stream; stream << "\n" << get_filename(location.file_name()) << "(" //<< location.line() << ") `" << location.function_name() << "`: "; << location.line() << "): "; ((stream << std::forward(ts)), ...); stream << std::endl; - log_queue.push(stream.str()); - if (log_func) { + log_channel.queue.push(stream.str()); + if (log_channel.func) { do { - log_func(std::move(log_queue.front())); - log_queue.pop(); - } while (!log_queue.empty()); + log_channel.func(std::move(log_channel.queue.front())); + log_channel.queue.pop(); + } while (!log_channel.queue.empty()); } } }; #define LOG_FUNC(name) \ private: \ - static log_func_t name##_func; \ - static log_queue_t name##_queue; \ + static inline log_channel_t name##_channel{}; \ public: \ - static void set_##name##_func(log_func_t log_func) { \ - name##_func = log_func; \ + static inline void set_##name##_func(log_func_t log_func) { \ + name##_channel.func = log_func; \ } \ template \ struct name { \ name(Ts&&... ts, source_location const& location = source_location::current()) { \ - log{ name##_func, name##_queue, std::forward(ts)..., location }; \ + log{ name##_channel, std::forward(ts)..., location }; \ } \ }; \ template \ -- cgit v1.2.3-56-ga3b1