-
Notifications
You must be signed in to change notification settings - Fork 6
/
Logger.cpp
48 lines (41 loc) · 1015 Bytes
/
Logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Logger.h"
#include "ModLoader.h"
#include <Windows.h>
#include <cstdio>
Logger::Logger(const char* modname) : m_modname(modname) {}
void Logger::Info(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
Log("INFO", fmt, args);
va_end(args);
}
void Logger::Warn(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
Log("WARN", fmt, args);
va_end(args);
}
void Logger::Error(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
Log("ERROR", fmt, args);
va_end(args);
}
void Logger::Log(const char* level, const char* fmt, va_list args) {
SYSTEMTIME sys;
GetLocalTime(&sys);
FILE* out_files[] = {
#ifdef _DEBUG
stdout,
#endif
ModLoader::m_instance->GetLogFile()
};
for (FILE* file : out_files) {
fprintf(file, "[%02d/%02d/%d %02d:%02d:%02d.%03d] ", sys.wMonth, sys.wDay,
sys.wYear, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
fprintf(file, "[%s/%s]: ", m_modname, level);
vfprintf(file, fmt, args);
fputc('\n', file);
fflush(file);
}
}