29 #include <boost/algorithm/string/case_conv.hpp>
31 #include <log4cpp/Category.hh>
32 #include <log4cpp/FileAppender.hh>
33 #include <log4cpp/OstreamAppender.hh>
34 #include <log4cpp/PatternLayout.hh>
35 #include <log4cpp/Priority.hh>
41 using log4cpp::Category;
42 using log4cpp::Layout;
43 using log4cpp::Priority;
50 {
"ERROR", Priority::ERROR},
51 {
"WARN", Priority::WARN},
52 {
"INFO", Priority::INFO},
53 {
"DEBUG", Priority::DEBUG}};
56 auto layout = make_unique<log4cpp::PatternLayout>();
57 layout->setConversionPattern(
"%d{%FT%T%Z} %c %5p : %m%n");
64 if (Category::getRoot().getAppender(
"console") ==
nullptr) {
65 log4cpp::OstreamAppender* consoleAppender =
new log4cpp::OstreamAppender{
"console", &
std::cerr};
67 Category::getRoot().addAppender(consoleAppender);
68 if (Category::getRoot().getPriority() == Priority::NOTSET) {
69 Category::setRootPriority(Priority::INFO);
72 return Logging{Category::getInstance(name)};
76 boost::to_upper(level);
79 Category::setRootPriority(it->second);
82 error_buffer <<
"Unrecognized logging level: " << level <<
std::endl;
88 Category& root = Category::getRoot();
89 root.removeAppender(root.getAppender(
"file"));
90 if (fileName.has_filename()) {
91 log4cpp::FileAppender* fileAppender =
new log4cpp::FileAppender(
"file", fileName.string());
93 root.addAppender(fileAppender);
95 root.setPriority(root.getPriority());
100 : m_logger(logger), m_log_func{log_func} {}
104 : m_logger(other.m_logger), m_log_func{other.m_log_func} {}
107 : m_logger(other.m_logger), m_log_func{other.
m_log_func} {}
110 (m_logger.*m_log_func)(m_message.str());