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>
42using log4cpp::Category;
44using log4cpp::Priority;
53 {
"FATAL", Priority::FATAL},
54 {
"ERROR", Priority::ERROR},
55 {
"WARN", Priority::WARN},
56 {
"INFO", Priority::INFO},
57 {
"DEBUG", Priority::DEBUG}
63 auto layout = make_unique<log4cpp::PatternLayout>();
64 layout->setConversionPattern(
"%d{%FT%T%Z} %c %5p : %m%n");
71 if (Category::getRoot().getAppender(
"console") ==
nullptr) {
72 log4cpp::OstreamAppender* consoleAppender =
new log4cpp::OstreamAppender{
"console", &
std::cerr};
74 Category::getRoot().addAppender(consoleAppender);
75 if (Category::getRoot().getPriority() == Priority::NOTSET) {
76 Category::setRootPriority(Priority::INFO);
79 return Logging{Category::getInstance(name)};
83 boost::to_upper(level);
86 Category::setRootPriority(it->second);
89 error_buffer <<
"Unrecognized logging level: " << level <<
std::endl;
95 Category& root = Category::getRoot();
96 root.removeAppender(root.getAppender(
"file"));
97 if (fileName.has_filename()) {
98 log4cpp::FileAppender* fileAppender =
new log4cpp::FileAppender(
"file", fileName.string());
100 root.addAppender(fileAppender);
102 root.setPriority(root.getPriority());
107 : m_logger(logger), m_log_func{log_func} {}
111 : m_logger(other.m_logger), m_log_func{other.m_log_func} {}
114 : m_logger(other.m_logger), m_log_func{other.m_log_func} {}
117 (m_logger.*m_log_func)(m_message.str());
This file is intended to iron out all the differences between different C++ standards.
defines the base Elements exception class
provide functions to retrieve configuration files
provide functions to retrieve resources pointed by environment variables
Elements base exception class.
A helper class for logging messages using the "<<" operator.
LogMessageStream(log4cpp::Category &logger, P_log_func log_func)
Logging API of the Elements framework.
static Logging getLogger(const std::string &name="")
static void setLogFile(const Path::Item &fileName)
Sets the file to store the log messages.
static void setLevel(std::string level)
Sets the global message level.
Logging(log4cpp::Category &log4cppLogger)
#define NON_REDUNDANT_MOVE(x)
unique_ptr< Layout > getLogLayout()
static const std::map< string, const int > LOG_LEVEL