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:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user