From c0a3e547f5d2c3d1cd6e83b81c279cdeeb5a1d32 Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 9 Aug 2024 20:59:34 -0400 Subject: [PATCH] add core::logf with log_file_out and log_to_console global args --- src/app/core/common.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/app/core/common.h b/src/app/core/common.h index c0b36693..4530a66c 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -10,6 +10,7 @@ #include #include +#include "absl/strings/str_format.h" #include "imgui/imgui.h" namespace yaze { @@ -181,17 +182,25 @@ class ImGuiIdIssuer { } }; +static bool log_to_console = false; +static std::string log_file_out = "log.txt"; + +template +static void logf(const absl::FormatSpec &format, const Args &...args) { + std::string message = absl::StrFormat(format, args...); + if (log_to_console) { + std::cout << message << std::endl; + } + static std::ofstream fout(log_file_out, std::ios::out | std::ios::app); + fout << message << std::endl; +} + class Logger { public: static void log(std::string message) { - static std::ofstream fout("log.txt", std::ios::out | std::ios::app); + static std::ofstream fout(log_file_out, std::ios::out | std::ios::app); fout << message << std::endl; } - - // log to console - static void logc(std::string message) { logs.emplace_back(message); } - - static std::vector logs; }; constexpr uint32_t kFastRomRegion = 0x808000;