forked from crosire/reshade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.cpp
51 lines (41 loc) · 1.12 KB
/
log.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
49
50
51
/**
* Copyright (C) 2014 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/reshade#license
*/
#include "log.hpp"
#include <Windows.h>
namespace reshade::log
{
std::ofstream stream;
message::message(level level)
{
SYSTEMTIME time;
GetLocalTime(&time);
const char level_names[][6] = { "INFO ", "ERROR", "WARN " };
stream << std::right << std::setfill('0')
<< std::setw(4) << time.wYear << '-'
<< std::setw(2) << time.wMonth << '-'
<< std::setw(2) << time.wDay << 'T'
<< std::setw(2) << time.wHour << ':'
<< std::setw(2) << time.wMinute << ':'
<< std::setw(2) << time.wSecond << ':'
<< std::setw(3) << time.wMilliseconds << ' '
<< '[' << std::setw(5) << GetCurrentThreadId() << ']' << std::setfill(' ')
<< " | " << level_names[static_cast<unsigned int>(level)] << " | " << std::left;
}
message::~message()
{
stream << std::endl;
}
bool open(const filesystem::path &path)
{
stream.open(path.wstring(), std::ios::out | std::ios::trunc);
if (!stream.is_open())
{
return false;
}
stream.setf(std::ios_base::showbase);
stream.flush();
return true;
}
}