blob: 333ae16c06e9e495a47e980a9b87422664c82f20 (
plain) (
blame)
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
|
#include "Logger.hpp"
/*void Logger::Log(const TelegramMessage& message, LogLevel logLevel) {
Log("[" + message->from->username + "] " + message->text, logLevel);
}*/
void Logger::Log(const string& inMsg, LogLevel logLevel) {
string outMsg;
#ifdef NDEBUG
if (logLevel == LogLevel::lDEBUG) {
// don't log debug messages in release mode
return;
}
#endif
// prefix message with time
outMsg = "[" + NOW_STRING + "]";
// TODO: let at least some (ERROR, WARN) levels go to stderr, not stdout
// prefix log level - TODO: allow filtering based on globally set level?
switch (logLevel) {
case LogLevel::lSTATUS:
outMsg += " [STATUS] " + inMsg;
break;
case LogLevel::lDEBUG:
outMsg += " [DEBUG] " + inMsg;
break;
case LogLevel::lINFO:
outMsg += " [INFO] " + inMsg;
break;
case LogLevel::lWARN:
outMsg += " [WARN] " + inMsg;
break;
case LogLevel::lERROR:
outMsg += " [ERROR] " + inMsg;
break;
}
Print(outMsg);
}
void Logger::Print(const string& msg) {
// console output
cout << msg << endl;
// file output | TODO: Logger needs state for that - or at least needs to pretend to have one
}
|