-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.h
60 lines (51 loc) · 951 Bytes
/
logging.h
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
/*
Simple c++ header for logging information and displaying information
*/
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#pragma once
#include <string>
#include <fstream>
#include <windows.h>
#include <iostream>
using namespace std;
class logging {
std::fstream logFile;
bool consoleEnabled;
public:
// Constructor
logging(bool enableConsole) {
if (enableConsole) {
consoleEnabled = true;
AllocConsole();
freopen("CONOUT$", "w", stdout);
}
else {
consoleEnabled = false;
}
}
// Log information to a file
bool logToFile(string fileName, string input) {
try {
logFile.open(fileName, ios::out);
logFile << input << endl;
logFile.close();
}
catch (int e) {
return false;
}
cout << input << endl;
return true;
}
// Log information to console
bool logToConsole(string input) {
if (consoleEnabled) {
cout << input << endl;
return true;
}
else {
return false;
}
}
};