From 839449e85decdf2a2eb6f350b375922f3bdf7855 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 5 Jan 2025 20:56:53 -0500 Subject: [PATCH] Improve logging and reformat CreateWindow call Updated common.h to include and absl/strings/str_cat.h. Modified logf to include a timestamp in log messages. Replaced log_to_console with ExperimentFlags::get().kLogToConsole. Removed newline character from logf output. Reformatted SDL_CreateWindow call in controller.cc for readability. --- src/app/core/common.h | 16 ++++++++++++---- src/app/core/controller.cc | 10 +++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/app/core/common.h b/src/app/core/common.h index 9110cbb7..a53e8ba6 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -1,6 +1,7 @@ #ifndef YAZE_CORE_COMMON_H #define YAZE_CORE_COMMON_H +#include #include #include #include @@ -10,6 +11,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" +#include "absl/strings/str_cat.h" namespace yaze { @@ -172,17 +174,23 @@ class NotifyValue { T temp_value_; }; -static bool log_to_console = false; static const std::string kLogFileOut = "yaze_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; + auto timestamp = std::chrono::system_clock::now(); + + std::time_t now_tt = std::chrono::system_clock::to_time_t(timestamp); + std::tm tm = *std::localtime(&now_tt); + message = absl::StrCat("[", tm.tm_hour, ":", tm.tm_min, ":", tm.tm_sec, "] ", + message, "\n"); + + if (ExperimentFlags::get().kLogToConsole) { + std::cout << message; } static std::ofstream fout(kLogFileOut, std::ios::out | std::ios::app); - fout << message << std::endl; + fout << message; } constexpr uint32_t kFastRomRegion = 0x808000; diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index 23862b92..e3fb8132 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -154,11 +154,11 @@ absl::Status Controller::CreateWindow() { window_ = std::unique_ptr( SDL_CreateWindow("Yet Another Zelda3 Editor", // window title - SDL_WINDOWPOS_UNDEFINED, // initial x position - SDL_WINDOWPOS_UNDEFINED, // initial y position - screen_width, // width, in pixels - screen_height, // height, in pixels - SDL_WINDOW_RESIZABLE), + SDL_WINDOWPOS_UNDEFINED, // initial x position + SDL_WINDOWPOS_UNDEFINED, // initial y position + screen_width, // width, in pixels + screen_height, // height, in pixels + SDL_WINDOW_RESIZABLE), core::SDL_Deleter()); if (window_ == nullptr) { return absl::InternalError(