forked from Ares-Developers/Syringe
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathLog.cpp
More file actions
62 lines (51 loc) · 961 Bytes
/
Log.cpp
File metadata and controls
62 lines (51 loc) · 961 Bytes
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
52
53
54
55
56
57
58
59
60
61
62
#include "Log.h"
#include <share.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
FileHandle Log::File;
void Log::Open(char const* const pFilename) noexcept
{
if (pFilename && *pFilename)
{
File = FileHandle(_fsopen(pFilename, "w", _SH_DENYWR));
}
}
void Log::Flush() noexcept
{
if (File)
{
fflush(File);
}
}
void Log::WriteTimestamp() noexcept
{
if (File)
{
time_t raw;
time(&raw);
tm t;
localtime_s(&t, &raw);
fprintf(File, "[%02d:%02d:%02d] ", t.tm_hour, t.tm_min, t.tm_sec);
}
}
void Log::WriteLine() noexcept
{
if (File)
{
fputs("\n", File);
}
}
void Log::WriteLine(char const* const pFormat, ...) noexcept
{
if (File)
{
va_list args;
va_start(args, pFormat);
WriteTimestamp();
vfprintf(File, pFormat, args);
WriteLine();
fflush(File);
va_end(args);
}
}