-
Notifications
You must be signed in to change notification settings - Fork 37
/
logger.cpp
57 lines (44 loc) · 1.31 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
53
54
55
56
57
#include "logger.hpp"
#include <QDate>
namespace Logging {
Logger::Logger(QObject *parent) :
QObject(parent)
{
}
void Logger::Log(const QString& facility, const QString& message, LogLevelE level)
{
QString dateTime(QDate::currentDate().toString("yyyy-MM-dd") +
QTime::currentTime().toString(" hh:mm:ss:zzz"));
// The logging levels are: [E]RROR [W]ARNING [I]NFORMATION [S]UCCESS.
QString levelFacility(QString("EWIS")[level] + " " + facility);
foreach(ILogTransport* transport, m_transports) {
transport->appendTime(dateTime);
transport->appendLevelAndFacility(level, levelFacility);
transport->appendMessage(message);
}
} // Log
bool Logger::AddTransport(ILogTransport* pTransport)
{
if(m_transports.contains(pTransport))
return false;
m_transports.append(pTransport);
return true;
} // AddTransport
bool Logger::RemoveTransport(ILogTransport* pTransport)
{
int index = m_transports.indexOf(pTransport);
if(-1 == index)
return false;
m_transports.removeAt(index);
return true;
} // RemoveTransport
Logger& getLoggerInstance()
{
static Logger theInstance;
return theInstance;
}
void Log(const QString &facility, const QString &message, LogLevelE level)
{
getLoggerInstance().Log(facility, message, level);
} // Log
} // namespace Logging