28#pragma warning(disable : 4996)
65 instance.mLevel = level;
70 instance.mFileOutputEnabled =
true;
75 instance.mFileOutputEnabled =
false;
80 instance.mFileOutput = output;
83 template<
typename... Args>
84 static void Trace(
const char *format, Args... args) {
88 template<
typename... Args>
89 static void Debug(
const char *format, Args... args) {
93 template<
typename... Args>
94 static void Info(
const char *format, Args... args) {
98 template<
typename... Args>
99 static void Warn(
const char *format, Args... args) {
103 template<
typename... Args>
104 static void Error(
const char *format, Args... args) {
108 template<
typename... Args>
109 static void Critical(
const char *format, Args... args) {
113 static void Trace(
const char *str) {
117 static void Debug(
const char *str) {
121 static void Info(
const char *str) {
125 static void Warn(
const char *str) {
129 static void Error(
const char *str) {
142 template<
typename... Args>
143 static void Log(
const Level level,
const char *tag,
const char *format, Args... args) {
145 std::lock_guard<std::mutex> lock(instance.mMutex);
146 if (instance.mLevel <= level) {
147 std::time_t t = std::time(
nullptr);
148 std::array<char, 100> time_buf{};
149 std::strftime(time_buf.data(),
sizeof time_buf,
"%Y-%m-%d %H:%M:%S", std::gmtime(&t));
150 std::printf(
"[%s] [%s] ", time_buf.data(), tag);
151 std::printf(format, args...);
153 if (instance.mFileOutputEnabled) {
154 std::FILE *file = std::fopen(instance.mFileOutput.c_str(),
"a");
155 std::fprintf(file,
"[%s] [%s] ", time_buf.data(), tag);
156 std::fprintf(file, format, args...);
157 std::fprintf(file,
"\n");
163 static void Log(
const Level level,
const char *tag,
const char *str) {
165 std::lock_guard<std::mutex> lock(instance.mMutex);
166 if (instance.mLevel <= level) {
167 std::time_t t = std::time(
nullptr);
168 std::array<char, 100> time_buf{};
169 std::strftime(time_buf.data(),
sizeof time_buf,
"%Y-%m-%d %H:%M:%S", std::gmtime(&t));
170 std::printf(
"[%s] [%s] %s\n", time_buf.data(), tag, str);
171 if (instance.mFileOutputEnabled) {
172 std::FILE *file = std::fopen(instance.mFileOutput.c_str(),
"a");
173 std::fprintf(file,
"[%s] [%s] %s\n", time_buf.data(), tag, str);
180 bool mFileOutputEnabled{
false};
181 std::string mFileOutput{
"default.log"};
Definition: Logger.hpp:39
static void SetFileOutput(const char *output)
Definition: Logger.hpp:78
static void Info(const char *str)
Definition: Logger.hpp:121
static void Trace(const char *format, Args... args)
Definition: Logger.hpp:84
static Logger & GetInstance()
Definition: Logger.hpp:58
static void SetLevel(const Level level)
Definition: Logger.hpp:63
static void Debug(const char *str)
Definition: Logger.hpp:117
static void DisableFileOutput()
Definition: Logger.hpp:73
static void Warn(const char *format, Args... args)
Definition: Logger.hpp:99
static void Critical(const char *format, Args... args)
Definition: Logger.hpp:109
Logger & operator=(const Logger &)=delete
static void Error(const char *format, Args... args)
Definition: Logger.hpp:104
static void Trace(const char *str)
Definition: Logger.hpp:113
static void Info(const char *format, Args... args)
Definition: Logger.hpp:94
static void EnableFileOutput()
Definition: Logger.hpp:68
static void Warn(const char *str)
Definition: Logger.hpp:125
static void Critical(const char *str)
Definition: Logger.hpp:133
Level
Definition: Logger.hpp:41
Logger(const Logger &)=delete
static void Debug(const char *format, Args... args)
Definition: Logger.hpp:89
Logger & operator=(Logger &&)=delete
static void Error(const char *str)
Definition: Logger.hpp:129