This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
basic_log.hpp
77 lines (62 loc) · 1.84 KB
/
basic_log.hpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <stdarg.h>
namespace Win11SysCheck
{
static void FileLog(const std::string& stFileName, const std::string& stLogData)
{
std::ofstream f(stFileName.c_str(), std::ofstream::out | std::ofstream::app);
f << stLogData.c_str() << std::endl;
f.close();
}
static void FileLogf(const std::string& stFileName, const char* c_szFormat, ...)
{
char szBuffer[8192] = { 0 };
va_list vaArgList;
va_start(vaArgList, c_szFormat);
vsprintf_s(szBuffer, c_szFormat, vaArgList);
va_end(vaArgList);
FileLog(stFileName.c_str(), szBuffer);
}
static void DebugLog(const char* c_szLogData)
{
OutputDebugStringA(c_szLogData);
}
static void DebugLogf(const char* c_szFormat, ...)
{
char szBuffer[8192] = { 0 };
va_list vaArgList;
va_start(vaArgList, c_szFormat);
vsprintf_s(szBuffer, c_szFormat, vaArgList);
va_end(vaArgList);
DebugLog(szBuffer);
}
static void ConsoleLog(const char* c_szLogData)
{
fputs(c_szLogData, stdout);
}
static void ConsoleLogf(const char* c_szFormat, ...)
{
char szBuffer[8192] = { 0 };
va_list vaArgList;
va_start(vaArgList, c_szFormat);
vsprintf_s(szBuffer, c_szFormat, vaArgList);
va_end(vaArgList);
ConsoleLog(szBuffer);
}
static void Logf(const std::string& stFileName, const char* c_szFormat, ...)
{
char szBuffer[8192] = { 0 };
va_list vaArgList;
va_start(vaArgList, c_szFormat);
vsprintf_s(szBuffer, c_szFormat, vaArgList);
va_end(vaArgList);
#ifdef _DEBUG
DebugLog(szBuffer);
#endif
ConsoleLog(szBuffer);
FileLog(stFileName.c_str(), szBuffer);
}
}