-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.cpp
More file actions
106 lines (93 loc) · 2.99 KB
/
logging.cpp
File metadata and controls
106 lines (93 loc) · 2.99 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
98
99
100
101
102
103
104
105
106
#include<iostream>
#include<string>
#include<fstream>
#include <chrono>
#include <ctime>
#include <algorithm>
#include "util.h"
using namespace std;
class logging {
private:
// set the logging leve
string level;
// set the output type either console or file
string stream;
// set the file path incase of output to file
string file_path;
// open the file for writing
ofstream file_out;
// logging priority
//int logging_level[4];
int curr_Loglevel;
public:
// override constructor for initialization the logging
logging(){
this->curr_Loglevel = 10;
//cout<<curr_Loglevel;
//this->level = level;
//set_logging_priority(priority, 4, level);
}
void set_level(string level){
if (level == "DEBUG")
curr_Loglevel = _DEBUG;
else if (level == "INFO")
curr_Loglevel = _INFO;
else if (level == "WARN")
curr_Loglevel = _WARN;
else if (level == "ERROR")
curr_Loglevel = _ERROR;
//else curr_Loglevel = 10;
}
void set_logging_priority(bool *pri, int size, string _level){
for (int i=0; i<size; i++)
cout<<pri[i];
}
// setting console output
void set_output_to_console(){
stream = "console";
cout<<"Stream set to console";
}
//Pending
// setting the output to the file
void set_output_to_file(string path){
//ofstream out;
file_out.open("log.txt");
if (file_out.is_open()){
stream = "file";
cout<<"Stream set to file ["<<path<<"]";
cout<<"File is loaded sucessfully";
}
else cout<<"Fail to load the file,there is some issue with path.Setting log level to console";
}
// Preparing message to log
string prepare_message(string str){
return "nothing";
}
// Retrieve the latest date/time
string get_current_timeDate(){
auto timenow = chrono::system_clock::to_time_t(chrono::system_clock::now());
string curr_time = ctime(&timenow);
curr_time.erase(std::remove(curr_time.begin(), curr_time.end(), '\n'), curr_time.end());
return curr_time;
}
void debug(string msg, int line, string file, string func, string str="null"){
// Debug log
if (_DEBUG >= curr_Loglevel)
LOGDEBUG(msg,line, file, func);
}
void warn(string msg, int line, string file, string func, string str="null"){
// Debug log
if (_WARN >= curr_Loglevel)
LOGWARN(msg, line, file, func);
}
void error(string msg, int line, string file, string func, string str="null"){
// Debug log
if (_ERROR >= curr_Loglevel)
LOGERROR(msg, line, file, func);
}
void info(string msg, int line, string file, string func, string str="null"){
// Debug log
if (_INFO >= curr_Loglevel)
LOGINFO(msg, line, file, func);
}
};