46 #ifndef OME_COMMON_LOG_H
47 #define OME_COMMON_LOG_H
52 #include <ome/common/config.h>
54 #ifdef OME_HAVE_BOOST_LOG
55 #define BOOST_LOG_DYN_LINK
56 #include <boost/log/core.hpp>
57 #include <boost/log/trivial.hpp>
58 #include <boost/log/expressions.hpp>
59 #include <boost/log/sources/severity_logger.hpp>
60 #include <boost/log/sources/severity_feature.hpp>
61 #include <boost/log/attributes/constant.hpp>
62 #else // ! OME_HAVE_BOOST_LOG
65 #endif // OME_HAVE_BOOST_LOG
70 #ifdef OME_HAVE_BOOST_LOG
71 namespace logging = boost::log;
91 #endif // OME_HAVE_BOOST_LOG
96 #ifdef OME_HAVE_BOOST_LOG
97 typedef logging::sources::severity_logger_mt<logging::trivial::severity_level>
Logger;
111 logger.add_attribute(
"ClassName", logging::attributes::constant<std::string>(className));
114 #else // ! OME_HAVE_BOOST_LOG
127 Logger(
const std::string& className):
132 className(
const std::string& className)
134 this->klass = className;
148 # pragma GCC diagnostic push
149 # pragma GCC diagnostic ignored "-Wswitch-default"
155 std::ostream& ostream;
156 logging::trivial::severity_level severity;
159 LogMessage(std::ostream& ostream,
160 logging::trivial::severity_level severity):
167 case logging::trivial:: trace:
170 case logging::trivial:: debug:
173 case logging::trivial:: info:
176 case logging::trivial:: warning:
179 case logging::trivial:: error:
182 case logging::trivial:: fatal:
187 ostream <<
'[' << sevstr <<
"] ";
209 # pragma GCC diagnostic pop
216 Logger logger(className);
220 #endif // OME_HAVE_BOOST_LOG
235 setLogLevel(logging::trivial::severity_level severity);
242 logging::trivial::severity_level
249 #ifndef OME_HAVE_BOOST_LOG
250 #define BOOST_LOG_SEV(logger, severity)\
251 if (severity >= ome::common::getLogLevel())\
252 ome::common::LogMessage(std::clog, severity).stream() << logger.className() << ": "
253 #endif // !OME_HAVE_BOOST_LOG
255 #endif // OME_COMMON_LOG_H
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
Message logger.
Definition: log.h:98
void setLogLevel(logging::trivial::severity_level severity)
Set global logging level.
Definition: log.cpp:63
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
Logger createLogger(const std::string &className)
Create a message logger for a class.
Definition: log.h:108
logging::trivial::severity_level getLogLevel()
Get global logging level.
Definition: log.cpp:75