diff options
author | hop311 <hop3114@gmail.com> | 2023-11-04 19:44:38 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-11-07 19:34:51 +0100 |
commit | b5bbeb47febc823517a5baba4eca66f32fb3609c (patch) | |
tree | 1a78d296f22d1cd17a84ce824974f9438a197074 /src/openvic-simulation/utility/Logger.hpp | |
parent | c1b7cab254ac14a173477661047ad2492930ff8b (diff) |
Cross-platform file lookup (case and separator)
Diffstat (limited to 'src/openvic-simulation/utility/Logger.hpp')
-rw-r--r-- | src/openvic-simulation/utility/Logger.hpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/openvic-simulation/utility/Logger.hpp b/src/openvic-simulation/utility/Logger.hpp index 04306f7..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,13 +78,13 @@ namespace OpenVic { struct log { log(log_channel_t& log_channel, Ts&&... ts, source_location const& location) { std::stringstream stream; - stream << 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() << "`: "; << location.line() << "): "; ((stream << std::forward<Ts>(ts)), ...); - stream << "\n" << std::endl; + stream << std::endl; log_channel.queue.push(stream.str()); if (log_channel.func) { do { |