Improve logging and reformat CreateWindow call

Updated common.h to include <chrono> 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.
This commit is contained in:
Justin Scofield
2025-01-05 20:56:53 -05:00
parent cf13d6bf9e
commit 839449e85d
2 changed files with 17 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
#ifndef YAZE_CORE_COMMON_H #ifndef YAZE_CORE_COMMON_H
#define YAZE_CORE_COMMON_H #define YAZE_CORE_COMMON_H
#include <chrono>
#include <cstdint> #include <cstdint>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@@ -10,6 +11,7 @@
#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_map.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "absl/strings/str_cat.h"
namespace yaze { namespace yaze {
@@ -172,17 +174,23 @@ class NotifyValue {
T temp_value_; T temp_value_;
}; };
static bool log_to_console = false;
static const std::string kLogFileOut = "yaze_log.txt"; static const std::string kLogFileOut = "yaze_log.txt";
template <typename... Args> template <typename... Args>
static void logf(const absl::FormatSpec<Args...> &format, const Args &...args) { static void logf(const absl::FormatSpec<Args...> &format, const Args &...args) {
std::string message = absl::StrFormat(format, args...); std::string message = absl::StrFormat(format, args...);
if (log_to_console) { auto timestamp = std::chrono::system_clock::now();
std::cout << message << std::endl;
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); static std::ofstream fout(kLogFileOut, std::ios::out | std::ios::app);
fout << message << std::endl; fout << message;
} }
constexpr uint32_t kFastRomRegion = 0x808000; constexpr uint32_t kFastRomRegion = 0x808000;

View File

@@ -154,11 +154,11 @@ absl::Status Controller::CreateWindow() {
window_ = std::unique_ptr<SDL_Window, core::SDL_Deleter>( window_ = std::unique_ptr<SDL_Window, core::SDL_Deleter>(
SDL_CreateWindow("Yet Another Zelda3 Editor", // window title SDL_CreateWindow("Yet Another Zelda3 Editor", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position SDL_WINDOWPOS_UNDEFINED, // initial y position
screen_width, // width, in pixels screen_width, // width, in pixels
screen_height, // height, in pixels screen_height, // height, in pixels
SDL_WINDOW_RESIZABLE), SDL_WINDOW_RESIZABLE),
core::SDL_Deleter()); core::SDL_Deleter());
if (window_ == nullptr) { if (window_ == nullptr) {
return absl::InternalError( return absl::InternalError(