32 #include "../Exception.h" 33 #include "../translator/Translator.h" 36 #include <boost/format.hpp> 37 #include <boost/filesystem/fstream.hpp> 38 #include <boost/log/attributes/current_process_name.hpp> 39 #include <boost/log/attributes/current_thread_id.hpp> 40 #include <boost/log/sinks/text_ostream_backend.hpp> 41 #include <boost/log/sources/severity_channel_logger.hpp> 42 #include <boost/log/trivial.hpp> 43 #include <boost/log/utility/setup/common_attributes.hpp> 44 #include <boost/log/utility/setup/file.hpp> 45 #include <boost/log/utility/setup/from_stream.hpp> 47 BOOST_LOG_ATTRIBUTE_KEYWORD(channel,
"Channel", std::string)
53 boost::log::sources::severity_channel_logger_mt<boost::log::trivial::severity_level, std::string> m_logger;
56 std::vector< std::string > m_logger_list;
73 boost::format err_msg(
TE_TR(
"There is already a logger registered using the configuration in file named: %1%"));
78 boost::filesystem::ifstream settings(filename);
79 boost::log::init_from_stream(settings);
81 m_pimpl->m_logger_list.push_back(filename);
91 boost::format err_msg(
TE_TR(
"There is already a logger registered with the name: %1%"));
97 format =
"[%TimeStamp%] <%Severity%>: %Message%";
99 boost::log::add_file_log(boost::log::keywords::auto_flush =
true,
100 boost::log::keywords::format = format,
101 boost::log::keywords::file_name = filename,
102 boost::log::keywords::channel = name,
103 boost::log::keywords::open_mode = std::ios_base::app,
104 boost::log::keywords::filter = (channel == name)
107 m_pimpl->m_logger_list.push_back(name);
112 return std::find_if(
m_pimpl->m_logger_list.begin(),
m_pimpl->m_logger_list.end(),
113 [&name](
const std::string& n)
114 {
return name == n; }) !=
m_pimpl->m_logger_list.end();
119 boost::log::core::get()->remove_all_sinks();
120 m_pimpl->m_logger_list.clear();
126 boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >(
"Severity");
128 boost::log::core::get()->add_global_attribute(
"Process",
129 boost::log::attributes::current_process_name());
130 boost::log::core::get()->add_global_attribute(
"ProcessID",
131 boost::log::attributes::current_process_id());
132 boost::log::core::get()->add_global_attribute(
"ThreadID",
133 boost::log::attributes::current_thread_id());
134 boost::log::add_common_attributes();
147 if(std::find(
m_pimpl->m_logger_list.begin(),
m_pimpl->m_logger_list.end(),
148 channel) ==
m_pimpl->m_logger_list.end())
151 boost::log::trivial::severity_level boost_severity;
154 case severity_level::trace :
155 boost_severity = boost::log::trivial::trace;
157 case severity_level::debug :
158 boost_severity = boost::log::trivial::debug;
160 case severity_level::info :
161 boost_severity = boost::log::trivial::info;
163 case severity_level::warning :
164 boost_severity = boost::log::trivial::warning;
166 case severity_level::error :
167 boost_severity = boost::log::trivial::error;
169 case severity_level::fatal :
170 boost_severity = boost::log::trivial::fatal;
177 BOOST_LOG_CHANNEL_SEV(
m_pimpl->m_logger, channel, boost_severity) << message;
This class is a singleton designed to manage log messages in TerraLib.
void log(const std::string &message, const std::string &channel, severity_level severity)
It logs a given string message, channel and severity.
void addLogger(const std::string &name, const std::string &filename, std::string format)
It sets the logger using a default implementation.
void addLoggerFromFile(const std::string &filename)
It sets the logger configuration from a given file.
Logger()
Singleton constructor must be private or protected.
#define TE_TR(message)
It marks a string in order to get translated.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
static Logger & instance()
It returns a reference to the singleton instance.
bool exists(const std::string &name)
Checks if exists a logger registered with the given name.
void removeAllLoggers()
It removes all added loggers.
This class is designed to manage the log of information in TerraLib.
~Logger()
Singleton destructor must be private or protected.
An exception indicating that a given argument is not valid, for instance if a given item already exis...