-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cpp
111 lines (86 loc) · 2.08 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
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
#include "Logger.hpp"
namespace logger = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
namespace cs_logger
{
Logger::Logger(const std::string& fileName)
{
initialize(fileName);
}
Logger::Logger(Logger const&)
{
}
Logger::~Logger()
{
}
Logger* Logger::logger_ = nullptr;
Logger* Logger::getInstance(const std::string& logFile)
{
if ( Logger::logger_ == nullptr )
Logger::logger_ = new Logger(logFile);
return Logger::logger_;
}
void Logger::initialize(const std::string& fileName)
{
boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");
boost::log::add_file_log(
fileName,
keywords::auto_flush = true,
keywords::format = "[%TimeStamp%] - %Severity%: %Message%"
);
//boost::log::core::get()->set_filter
//(
// boost::log::trivial::severity >= boost::log::trivial::info
//);
boost::log::add_common_attributes();
}
void Logger::logInfo(const std::string& message)
{
BOOST_LOG_SEV(log_, info) << message;
}
void Logger::logDebug(const std::string& message)
{
BOOST_LOG_SEV(log_, debug) << message;
}
void Logger::logWarn(const std::string& message)
{
BOOST_LOG_SEV(log_, warning) << message;
}
void Logger::logError(const std::string& message)
{
BOOST_LOG_SEV(log_, error) << message;
}
void Logger::logFatal(const std::string& message)
{
BOOST_LOG_SEV(log_, fatal) << message;
}
// Wide String versions
void Logger::logInfo(const std::wstring& message)
{
BOOST_LOG_SEV(log_, info) << message;
}
void Logger::logDebug(const std::wstring& message)
{
BOOST_LOG_SEV(log_, debug) << message;
}
void Logger::logWarn(const std::wstring& message)
{
BOOST_LOG_SEV(log_, warning) << message;
}
void Logger::logError(const std::wstring& message)
{
BOOST_LOG_SEV(log_, error) << message;
}
void Logger::logFatal(const std::wstring& message)
{
BOOST_LOG_SEV(log_, fatal) << message;
}
src::severity_logger< severity_level >& Logger::getLogger()
{
return log_;
}
}