yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1#ifndef YAZE_UTIL_LOG_H
2#define YAZE_UTIL_LOG_H
3
4#include <chrono>
5#include <cstdint>
6#include <fstream>
7#include <iostream>
8#include <string>
9
10#include "absl/strings/str_cat.h"
11#include "absl/strings/str_format.h"
12#include "app/core/features.h"
13
14namespace yaze {
15namespace util {
16
17static const std::string kLogFileOut = "yaze_log.txt";
18
19template <typename... Args>
20static void logf(const absl::FormatSpec<Args...> &format, const Args &...args) {
21 std::string message = absl::StrFormat(format, args...);
22 auto timestamp = std::chrono::system_clock::now();
23
24 std::time_t now_tt = std::chrono::system_clock::to_time_t(timestamp);
25 std::tm tm = *std::localtime(&now_tt);
26 message = absl::StrCat("[", tm.tm_hour, ":", tm.tm_min, ":", tm.tm_sec, "] ",
27 message, "\n");
28
29 if (core::FeatureFlags::get().kLogToConsole) {
30 std::cout << message;
31 }
32 static std::ofstream fout(kLogFileOut, std::ios::out | std::ios::app);
33 fout << message;
34}
35
36} // namespace util
37} // namespace yaze
38
39#endif // YAZE_UTIL_LOG_H
static Flags & get()
Definition features.h:69
Main namespace for the application.
Definition controller.cc:18