diff options
author | Hop311 <Hop3114@gmail.com> | 2023-11-07 22:38:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 22:38:07 +0100 |
commit | ae2742113ec7283a2a5afa62f8bfd98a865c4208 (patch) | |
tree | 601591215af0c6724766019ebb577141ea5807c5 /src/openvic-simulation/utility/Logger.hpp | |
parent | 1603fbafb1c03830f38fefd87d8bd0d7d3f135a2 (diff) | |
parent | d30421fa7d7f6ad87d3f90cc0ab491742f0d2548 (diff) |
Merge pull request #64 from OpenVicProject/modifier-instance
ModifierEffects stored as instances
Diffstat (limited to 'src/openvic-simulation/utility/Logger.hpp')
-rw-r--r-- | src/openvic-simulation/utility/Logger.hpp | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/openvic-simulation/utility/Logger.hpp b/src/openvic-simulation/utility/Logger.hpp index a1c599d..20c7fdd 100644 --- a/src/openvic-simulation/utility/Logger.hpp +++ b/src/openvic-simulation/utility/Logger.hpp @@ -1,12 +1,16 @@ #pragma once #include <functional> +#include <iostream> #include <queue> #include <sstream> + #ifdef __cpp_lib_source_location #include <source_location> #endif +#include "openvic-simulation/utility/StringUtils.hpp" + namespace OpenVic { #ifndef __cpp_lib_source_location @@ -52,8 +56,17 @@ namespace OpenVic { #endif public: - static void set_logger_funcs(); - static char const* get_filename(char const* filepath, char const* default_path = nullptr); + static void set_logger_funcs() { + set_info_func([](std::string&& str) { + std::cout << "[INFO] " << str; + }); + set_warning_func([](std::string&& str) { + std::cerr << "[WARNING] " << str; + }); + set_error_func([](std::string&& str) { + std::cerr << "[ERROR] " << str; + }); + } private: struct log_channel_t { @@ -65,7 +78,7 @@ namespace OpenVic { struct log { log(log_channel_t& log_channel, Ts&&... ts, source_location const& location) { std::stringstream stream; - stream << "\n" << get_filename(location.file_name()) << "(" + stream << StringUtils::get_filename(location.file_name()) << "(" /* Function name removed to reduce clutter. It is already included * in Godot's print functions, so this was repeating it. */ //<< location.line() << ") `" << location.function_name() << "`: "; @@ -83,20 +96,21 @@ namespace OpenVic { }; #define LOG_FUNC(name) \ - private: \ - static inline log_channel_t name##_channel {}; \ - public: \ - static inline void set_##name##_func(log_func_t log_func) { \ - name##_channel.func = log_func; \ +private: \ + static inline log_channel_t name##_channel {}; \ +\ +public: \ + static inline void set_##name##_func(log_func_t log_func) { \ + name##_channel.func = log_func; \ + } \ + template<typename... Ts> \ + struct name { \ + name(Ts&&... ts, source_location const& location = source_location::current()) { \ + log<Ts...> { name##_channel, std::forward<Ts>(ts)..., location }; \ } \ - template<typename... Ts> \ - struct name { \ - name(Ts&&... ts, source_location const& location = source_location::current()) { \ - log<Ts...> { name##_channel, std::forward<Ts>(ts)..., location }; \ - } \ - }; \ - template<typename... Ts> \ - name(Ts&&...) -> name<Ts...>; + }; \ + template<typename... Ts> \ + name(Ts&&...) -> name<Ts...>; LOG_FUNC(info) LOG_FUNC(warning) |