-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·142 lines (122 loc) · 3.96 KB
/
main.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//////////////////////////////////////////////////////////////////////////////
// @File Name: Main.cpp //
// @Author: Prajilal KP //
// @Version: 0.0.1 //
// @L.M.D: 27th April 2018 //
// @Description: Test Class //
// //
// Detail Description: //
// Test file for Logger. //
// //
//////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "Logger.h"
using namespace std;
using namespace cpplogger;
void CallLogExampleOne();
void CallLogExampleTwo(int val);
void CallLogExampleThree();
int main(void)
{
try {
string aplLogFile = "apl.log";
string dbgLogFile = "debug.log";
string evntLogFile = "event.log";
// Initialize the logger with log (application, event, debug) file paths
Logger::Init(aplLogFile, dbgLogFile, evntLogFile);
// Set file logging to true
Logger::EnableFileLogging(true);
// Set console logging to true
Logger::EnableConsoleLogging(true);
// Set logging severity level to INFO
Logger::SetLogSeverityLevel(INFO);
// Application startup log
Logger::Info(LOGGER_CODE_INFO_APP_START, L"Starting the application...");
// INFO level
Logger::Info(L"Information level logging (%u)", 1);
// ERROR level
Logger::Error(L"Error level logging (%u)", 1);
// Critical level
Logger::Crit(L"Critical level logging (%u)", 1);
// WARN level
Logger::Warn(L"Warning level logging (%u)", 1);
// DEBUG level
Logger::Debug(L"Debug level logging (%u)", 1);
// EVENT level
Logger::Event(L"Event: {application has started}");
//syslog() examples
// INFO level
Logger::SysLogInfo(L"syslog() information level logging");
// ERROR level
Logger::SysLogError(L"syslog() error level logging");
// Critical level
Logger::SysLogCrit(L"syslog() critical level logging");
// WARN level
Logger::SysLogWarn(L"syslog() warning level logging");
// DEBUG level
Logger::SysLogDebug(L"syslog() debug level logging");
// Application end log
Logger::Info(LOGGER_CODE_INFO_APP_STOP, L"Stopping the application...");
//CallLog example
CallLogExampleOne();
CallLogExampleTwo(25);
CallLogExampleThree();
// Release and close all loggers
try {
Logger::DropAll();
} catch (LoggerException& le) {
Logger::SysLogError(L"%s", le.GetMsg());
}
} catch (LoggerException& le) {
// Log exception and exit
Logger::SysLogCrit(L"Failed to start (%s)", le.GetMsg());
try {
Logger::DropAll();
} catch (LoggerException& le) {
Logger::SysLogError(L"%s", le.GetMsg());
}
exit(EXIT_FAILURE);
} catch (std::exception &e) {
// Log exception and exit
Logger::SysLogCrit(L"Failed to start (%s)", e.what());
try {
Logger::DropAll();
} catch (LoggerException& le) {
Logger::SysLogError(L"%s", le.GetMsg());
}
exit(EXIT_FAILURE);
} catch (...) {
// Log exception and exit
Logger::SysLogCrit(L"Failed to start (unknown exception)");
try {
Logger::DropAll();
} catch (LoggerException& le) {
Logger::SysLogError(L"%s", le.GetMsg());
}
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
/*
* CallLogExampleOne()
*/
void CallLogExampleOne() {
CallLog(L"%s::%s()", __FILE__, __func__);
Logger::Event(L"CallLogExampleOne() has executed");
}
/*
* CallLogExampleTwo()
*/
void CallLogExampleTwo(int val)
{
CallLog(L"%s::%s(val= %d)", __FILE__, __func__, val);
Logger::Event(L"CallLogExampleTwo() has executed");
}
/*
* CallLogExampleThree()
*/
void CallLogExampleThree()
{
CallLog log(__FILE__, __LINE__, __func__);
Logger::Event(L"CallLogExampleThree() has executed");
}