-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlogConsole.cpp
More file actions
52 lines (44 loc) · 1.12 KB
/
Copy pathlogConsole.cpp
File metadata and controls
52 lines (44 loc) · 1.12 KB
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
#include "stdafx.h"
#include "logConsole.h"
using namespace std;
HANDLE hConsole;
namespace function {
namespace console {
void start() {
AllocConsole();
freopen("CONOUT$", "w", stdout);
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
}
void message(char *msg, DWORD type, bool showType, bool p_time, bool p_newline) {
switch (type) {
case 0:
SetConsoleTextAttribute(hConsole, 63);
if (showType) cout << "[INFO]";
break;
case 1:
SetConsoleTextAttribute(hConsole, 79);
if (showType) cout << "[ERROR]";
break;
case 2:
SetConsoleTextAttribute(hConsole, 111);
if (showType) cout << "[WARNING]";
break;
case 3:
SetConsoleTextAttribute(hConsole, 143);
if (showType) cout << "[DEBUG]";
break;
}
if (p_time) {
time_t now = time(0);
tm *ltm = localtime(&now);
cout << "["
<< setfill('0') << setw(2) << ltm->tm_hour << ":"
<< setfill('0') << setw(2) << ltm->tm_min << ":"
<< setfill('0') << setw(2) << ltm->tm_sec << "]";
}
cout << " " << msg;
if (p_newline) cout << std::endl;
SetConsoleTextAttribute(hConsole, 15);
}
}
}