forked from filgy/watcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.cpp
54 lines (37 loc) · 1.1 KB
/
logger.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
#include "logger.h"
fstream* logger::fileHandler = NULL;
loggerFlags logger::errorReporting = E_ERROR;
bool logger::verbose = false;
void logger::setErrorReporting(loggerFlags flag){
logger::errorReporting = flag;
}
void logger::setVerbose(bool verbose){
logger::verbose = verbose;
}
bool logger::open(string fileName){
logger::fileHandler = new fstream(fileName.c_str(), ios::out);
if(logger::fileHandler->is_open())
return true;
delete logger::fileHandler;
return false;
}
bool logger::write(string message, loggerFlags flag){
if(flag < logger::errorReporting)
return false;
message = ((flag >= E_WARNING)? "[!] " : "[*] ") + message;
if(logger::verbose)
cout << message << endl;
if(logger::fileHandler && logger::fileHandler->is_open()){
*(logger::fileHandler) << message << endl;
return true;
}
return false;
}
bool logger::close(){
if(logger::fileHandler && logger::fileHandler->is_open()){
logger::fileHandler->close();
delete logger::fileHandler;
return true;
}
return false;
}