-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestLogger.cpp
More file actions
97 lines (78 loc) · 2.1 KB
/
testLogger.cpp
File metadata and controls
97 lines (78 loc) · 2.1 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "CPPLogger.h"
#include <thread>
#include <unistd.h>
#include <iostream>
class simpleCustomLogger : public CustomLogger
{
public:
void writeLogString(std::string message)
{
std::cout << "Custom - " << message << std::endl;
}
};
void sendLogs()
{
LOG(DEBUG) << "Log 1";
LOG(INFO) << "Log 2";
LOG(WARN) << "Log 3";
LOG(ERROR) << "Log 4";
LOG(FATAL) << "Log 5";
}
void threadedSendLogs()
{
for(int i = 0; i < 10; i++)
{
LOG(DEBUG) << "Iteration " << i << " in thread " << std::this_thread::get_id();
sendLogs();
usleep(100000);
}
}
int runTest()
{
CPPLogger::getLog().setLogLevel(DEBUG);
std::cout << "All Logs\n";
sendLogs();
std::cout << std::endl;
CPPLogger::getLog().setLogLevel(INFO);
std::cout << "Info or higher\n";
sendLogs();
std::cout << std::endl;
CPPLogger::getLog().setLogLevel(WARN);
std::cout << "Warning or higher\n";
sendLogs();
std::cout << std::endl;
CPPLogger::getLog().setLogLevel(ERROR);
std::cout << "Error or Higher\n";
sendLogs();
std::cout << std::endl;
CPPLogger::getLog().setLogLevel(FATAL);
std::cout << "Fatal or higher\n";
sendLogs();
std::cout << std::endl;
CPPLogger::getLog().setLogLevel(DEBUG);
std::thread thread1(threadedSendLogs);
std::thread thread2(threadedSendLogs);
thread1.join();
thread2.join();
return 0;
}
int main()
{
/*CPPLogger::getLog().unSetLogMode(LOGMODE_STDOUT);
std::cout << "Running log test for stdout only. " << std::endl << std::endl;
runTest();
std::cout << "Running test for file only. " << std::endl << std::endl;
CPPLogger::getLog().setLogModeFile("/tmp/testlog_fonly.log");
CPPLogger::getLog().unSetLogMode(LOGMODE_STDOUT);
runTest();
std::cout << "Running test with both stdout and file "<< std::endl << std::endl;
CPPLogger::getLog().setLogModeFile("/tmp/testlog_both.log");
CPPLogger::getLog().setLogModeStdOut();
runTest();
*/
CPPLogger::getLog().unSetLogMode(LOGMODE_FILE);
CPPLogger::getLog().unSetLogMode(LOGMODE_STDOUT);
CPPLogger::getLog().setLogModeCustom(new simpleCustomLogger());
runTest();
return 0;
}