29 #include <boost/algorithm/string/case_conv.hpp>
30 #include <boost/filesystem/path.hpp>
32 #include <log4cpp/Category.hh>
33 #include <log4cpp/FileAppender.hh>
34 #include <log4cpp/OstreamAppender.hh>
35 #include <log4cpp/PatternLayout.hh>
36 #include <log4cpp/Priority.hh>
42 using log4cpp::Category;
43 using log4cpp::Priority;
44 using log4cpp::Layout;
49 {
"ERROR", Priority::ERROR},
50 {
"WARN", Priority::WARN},
51 {
"INFO", Priority::INFO},
52 {
"DEBUG", Priority::DEBUG}};
55 log4cpp::PatternLayout* layout =
new log4cpp::PatternLayout {};
56 layout->setConversionPattern(
"%d{%FT%T%Z} %c %5p : %m%n");
61 : m_log4cppLogger(log4cppLogger) { }
64 if (Category::getRoot().getAppender(
"console") == NULL) {
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)};
77 boost::to_upper(level);
80 Category::setRootPriority(it->second);
83 error_buffer <<
"Unrecognized logging level: " << level <<
std::endl;
89 Category& root = Category::getRoot();
90 root.removeAppender(root.getAppender(
"file"));
91 if (fileName.has_filename()) {
92 log4cpp::FileAppender* fileAppender =
new log4cpp::FileAppender(
"file", fileName.string());
94 root.addAppender(fileAppender);
96 root.setPriority(root.getPriority());
101 : m_logger(logger), m_log_func{log_func} { }
105 : m_logger(other.m_logger), m_log_func{other.m_log_func} { }
108 (m_logger.*m_log_func) (m_message.str());
unique_ptr< Layout > getLogLayout()
A helper class for logging messages using the "<<" operator.
Logging(log4cpp::Category &log4cppLogger)
Logging API of the Elements framework.
boost::filesystem::path path
static void setLogFile(const boost::filesystem::path &fileName)
Sets the file to store the log messages.
static void setLevel(std::string level)
Sets the global message level.
static const std::map< string, const int > LOG_LEVEL
static Logging getLogger(const std::string &name="")
defines the base Elements exception class
LogMessageStream(log4cpp::Category &logger, P_log_func log_func)