32 #ifndef LSST_LOG_LOG_H
33 #define LSST_LOG_LOG_H
43 #include <log4cxx/logger.h>
44 #include <boost/format.hpp>
52 #define LOG_CONFIG(filename) lsst::log::Log::configure(filename)
66 #define LOG_CONFIG_PROP(string) lsst::log::Log::configure_prop(string)
75 #define LOG_GET(logger) lsst::log::Log::getLogger(logger)
85 #define LOG_GET_CHILD(logger, suffix) lsst::log::Log::getLogger(logger).getChild(suffix)
97 #define LOG_MDC(key, value) lsst::log::Log::MDC(key, value)
105 #define LOG_MDC_REMOVE(key) lsst::log::Log::MDCRemove(key)
118 #define LOG_CONCAT_IMPL(a, b) a ## b
119 #define LOG_CONCAT_IMPL2(a, b) LOG_CONCAT_IMPL(a, b)
120 #define LOG_MDC_SCOPE(key, value) lsst::log::LogMDCScope LOG_CONCAT_IMPL2(_log_mdc_scope_, __COUNTER__)(key, value);
142 #define LOG_MDC_INIT(func) lsst::log::Log::MDCRegisterInit(std::function<void()>(func))
151 #define LOG_SET_LVL(logger, level) \
152 lsst::log::Log::getLogger(logger).setLevel(level)
162 #define LOG_GET_LVL(logger) \
163 lsst::log::Log::getLogger(logger).getLevel()
173 #define LOG_GETEFF_LVL(logger) \
174 lsst::log::Log::getLogger(logger).getEffectiveLevel()
185 #define LOG_CHECK_LVL(logger, level) \
186 lsst::log::Log::getLogger(logger).isEnabledFor(level)
194 #define LOG_CHECK_TRACE() \
195 LOG4CXX_UNLIKELY(lsst::log::Log::getDefaultLogger().isTraceEnabled())
203 #define LOG_CHECK_DEBUG() \
204 LOG4CXX_UNLIKELY(lsst::log::Log::getDefaultLogger().isDebugEnabled())
212 #define LOG_CHECK_INFO() \
213 lsst::log::Log::getDefaultLogger().isInfoEnabled()
221 #define LOG_CHECK_WARN() \
222 lsst::log::Log::getDefaultLogger().isWarnEnabled()
230 #define LOG_CHECK_ERROR() \
231 lsst::log::Log::getDefaultLogger().isErrorEnabled()
239 #define LOG_CHECK_FATAL() \
240 lsst::log::Log::getDefaultLogger().isFatalEnabled()
251 #define LOG(logger, level, message...) \
253 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
254 if (log.isEnabledFor(level)) { \
255 log.log(log4cxx::Level::toLevel(level), LOG4CXX_LOCATION, message); } \
266 #define LOG_TRACE(message...) \
268 lsst::log::Log log; \
269 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
270 log.log(log4cxx::Level::getTrace(), LOG4CXX_LOCATION, message); } \
281 #define LOG_DEBUG(message...) \
283 lsst::log::Log log; \
284 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
285 log.log(log4cxx::Level::getDebug(), LOG4CXX_LOCATION, message); } \
296 #define LOG_INFO(message...) \
298 lsst::log::Log log; \
299 if (log.isInfoEnabled()) { \
300 log.log(log4cxx::Level::getInfo(), LOG4CXX_LOCATION, message); } \
311 #define LOG_WARN(message...) \
313 lsst::log::Log log; \
314 if (log.isWarnEnabled()) { \
315 log.log(log4cxx::Level::getWarn(), LOG4CXX_LOCATION, message); } \
326 #define LOG_ERROR(message...) \
328 lsst::log::Log log; \
329 if (log.isErrorEnabled()) { \
330 log.log(log4cxx::Level::getError(), LOG4CXX_LOCATION, message); } \
341 #define LOG_FATAL(message...) \
343 lsst::log::Log log; \
344 if (log.isFatalEnabled()) { \
345 log.log(log4cxx::Level::getFatal(), LOG4CXX_LOCATION, message); } \
350 #define LOG_MESSAGE_VIA_STREAM_(logger, level, message) \
351 std::ostringstream stream_; \
352 stream_ << message; \
353 logger.logMsg(level, LOG4CXX_LOCATION, stream_.str())
369 #define LOGS(logger, level, message) \
371 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
372 if (log.isEnabledFor(level)) { \
373 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::toLevel(level), message); \
388 #define LOGS_TRACE(message) \
390 lsst::log::Log log; \
391 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
392 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getTrace(), message); \
407 #define LOGS_DEBUG(message) \
409 lsst::log::Log log; \
410 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
411 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getDebug(), message); \
426 #define LOGS_INFO(message) \
428 lsst::log::Log log; \
429 if (log.isInfoEnabled()) { \
430 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getInfo(), message); \
445 #define LOGS_WARN(message) \
447 lsst::log::Log log; \
448 if (log.isWarnEnabled()) { \
449 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getWarn(), message); \
464 #define LOGS_ERROR(message) \
466 lsst::log::Log log; \
467 if (log.isErrorEnabled()) { \
468 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getError(), message); \
483 #define LOGS_FATAL(message) \
485 lsst::log::Log log; \
486 if (log.isFatalEnabled()) { \
487 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getFatal(), message); \
499 #define LOGL_TRACE(logger, message...) \
501 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
502 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
503 log.log(log4cxx::Level::getTrace(), LOG4CXX_LOCATION, message);\
515 #define LOGL_DEBUG(logger, message...) \
517 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
518 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
519 log.log(log4cxx::Level::getDebug(), LOG4CXX_LOCATION, message); \
531 #define LOGL_INFO(logger, message...) \
533 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
534 if (log.isInfoEnabled()) { \
535 log.log(log4cxx::Level::getInfo(), LOG4CXX_LOCATION, message); \
547 #define LOGL_WARN(logger, message...) \
549 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
550 if (log.isWarnEnabled()) { \
551 log.log(log4cxx::Level::getWarn(), LOG4CXX_LOCATION, message); \
563 #define LOGL_ERROR(logger, message...) \
565 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
566 if (log.isErrorEnabled()) { \
567 log.log(log4cxx::Level::getError(), LOG4CXX_LOCATION, message); \
579 #define LOGL_FATAL(logger, message...) \
581 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
582 if (log.isFatalEnabled()) { \
583 log.log(log4cxx::Level::getFatal(), LOG4CXX_LOCATION, message); \
599 #define LOGLS_TRACE(logger, message) \
601 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
602 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
603 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getTrace(), message); \
619 #define LOGLS_DEBUG(logger, message) \
621 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
622 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
623 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getDebug(), message); \
639 #define LOGLS_INFO(logger, message) \
641 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
642 if (log.isInfoEnabled()) { \
643 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getInfo(), message); \
659 #define LOGLS_WARN(logger, message) \
661 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
662 if (log.isWarnEnabled()) { \
663 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getWarn(), message); \
679 #define LOGLS_ERROR(logger, message) \
681 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
682 if (log.isErrorEnabled()) { \
683 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getError(), message); \
699 #define LOGLS_FATAL(logger, message) \
701 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
702 if (log.isFatalEnabled()) { \
703 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getFatal(), message); \
707 #define LOG_LVL_TRACE static_cast<int>(log4cxx::Level::TRACE_INT)
708 #define LOG_LVL_DEBUG static_cast<int>(log4cxx::Level::DEBUG_INT)
709 #define LOG_LVL_INFO static_cast<int>(log4cxx::Level::INFO_INT)
710 #define LOG_LVL_WARN static_cast<int>(log4cxx::Level::WARN_INT)
711 #define LOG_LVL_ERROR static_cast<int>(log4cxx::Level::ERROR_INT)
712 #define LOG_LVL_FATAL static_cast<int>(log4cxx::Level::FATAL_INT)
714 #define LOG_LOGGER lsst::log::Log
730 Log() : _logger(_defaultLogger()) { }
779 void log(log4cxx::LevelPtr level,
780 log4cxx::spi::LocationInfo
const& location,
781 char const* fmt, ...);
782 void logMsg(log4cxx::LevelPtr level,
783 log4cxx::spi::LocationInfo
const& location,
794 static log4cxx::LoggerPtr
const& _defaultLogger();
804 log4cxx::LoggerPtr _logger;
826 _oldValue = other._oldValue;
831 if (not _key.
empty()) {
832 if (_oldValue.
empty()) {
839 _oldValue = other._oldValue;
848 if (not _key.
empty()) {
849 if (_oldValue.
empty()) {
This static class includes a variety of methods for interacting with the the logging module.
bool isErrorEnabled() const
Check whether the logger is enabled for the ERROR Level.
static Log getDefaultLogger()
Return default logger instance, same as default constructor.
static Log getLogger(Log const &logger)
static void MDCRemove(std::string const &key)
Remove the value associated with KEY within the MDC.
int getLevel() const
Retrieve the logging threshold.
bool isEnabledFor(int level) const
Return whether the logging threshold of the logger is less than or equal to LEVEL.
void logMsg(log4cxx::LevelPtr level, log4cxx::spi::LocationInfo const &location, std::string const &msg)
Method used by LOGS_INFO and similar macros to process a log message.
bool isTraceEnabled() const
Check whether the logger is enabled for the TRACE Level.
Log getChild(std::string const &suffix) const
Return a logger which is a descendant to this logger.
static void configure_prop(std::string const &properties)
Configures log4cxx using a string containing the list of properties, equivalent to configuring from a...
bool isInfoEnabled() const
Check whether the logger is enabled for the INFO Level.
void setLevel(int level)
Set the logging threshold to LEVEL.
bool isWarnEnabled() const
Check whether the logger is enabled for the WARN Level.
bool isDebugEnabled() const
Check whether the logger is enabled for the DEBUG Level.
bool isFatalEnabled() const
Check whether the logger is enabled for the FATAL Level.
static void configure()
Explicitly configures log4cxx and initializes logging system.
static std::string MDC(std::string const &key, std::string const &value)
Places a KEY/VALUE pair in the Mapped Diagnostic Context (MDC) for the current thread.
static int MDCRegisterInit(std::function< void()> function)
void log(log4cxx::LevelPtr level, log4cxx::spi::LocationInfo const &location, char const *fmt,...)
Method used by LOG_INFO and similar macros to process a log message with variable arguments along wit...
std::string getName() const
Get the logger name associated with the Log object.
int getEffectiveLevel() const
Retrieve the effective logging threshold.
LogMDCScope & operator=(LogMDCScope &&other)
LogMDCScope & operator=(LogMDCScope const &)=delete
LogMDCScope(LogMDCScope const &)=delete
LogMDCScope(std::string const &key, std::string const &value)
Constructor adds KEY/VALUE pair to current thread MDC.
~LogMDCScope()
Destructor restores old key value in MDC.
LogMDCScope(LogMDCScope &&other)
unsigned lwpID()
Function which returns LWP ID on platforms which support it.
A base class for image defects.