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) 127 #define LOG_MDC_INIT(func) lsst::log::Log::MDCRegisterInit(std::function<void()>(func)) 136 #define LOG_SET_LVL(logger, level) \ 137 lsst::log::Log::getLogger(logger).setLevel(level) 147 #define LOG_GET_LVL(logger) \ 148 lsst::log::Log::getLogger(logger).getLevel() 159 #define LOG_CHECK_LVL(logger, level) \ 160 lsst::log::Log::getLogger(logger).isEnabledFor(level) 168 #define LOG_CHECK_TRACE() \ 169 LOG4CXX_UNLIKELY(lsst::log::Log::getDefaultLogger().isTraceEnabled()) 177 #define LOG_CHECK_DEBUG() \ 178 LOG4CXX_UNLIKELY(lsst::log::Log::getDefaultLogger().isDebugEnabled()) 186 #define LOG_CHECK_INFO() \ 187 lsst::log::Log::getDefaultLogger().isInfoEnabled() 195 #define LOG_CHECK_WARN() \ 196 lsst::log::Log::getDefaultLogger().isWarnEnabled() 204 #define LOG_CHECK_ERROR() \ 205 lsst::log::Log::getDefaultLogger().isErrorEnabled() 213 #define LOG_CHECK_FATAL() \ 214 lsst::log::Log::getDefaultLogger().isFatalEnabled() 225 #define LOG(logger, level, message...) \ 227 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 228 if (log.isEnabledFor(level)) { \ 229 log.log(log4cxx::Level::toLevel(level), LOG4CXX_LOCATION, message); } \ 240 #define LOG_TRACE(message...) \ 242 lsst::log::Log log; \ 243 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \ 244 log.log(log4cxx::Level::getTrace(), LOG4CXX_LOCATION, message); } \ 255 #define LOG_DEBUG(message...) \ 257 lsst::log::Log log; \ 258 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \ 259 log.log(log4cxx::Level::getDebug(), LOG4CXX_LOCATION, message); } \ 270 #define LOG_INFO(message...) \ 272 lsst::log::Log log; \ 273 if (log.isInfoEnabled()) { \ 274 log.log(log4cxx::Level::getInfo(), LOG4CXX_LOCATION, message); } \ 285 #define LOG_WARN(message...) \ 287 lsst::log::Log log; \ 288 if (log.isWarnEnabled()) { \ 289 log.log(log4cxx::Level::getWarn(), LOG4CXX_LOCATION, message); } \ 300 #define LOG_ERROR(message...) \ 302 lsst::log::Log log; \ 303 if (log.isErrorEnabled()) { \ 304 log.log(log4cxx::Level::getError(), LOG4CXX_LOCATION, message); } \ 315 #define LOG_FATAL(message...) \ 317 lsst::log::Log log; \ 318 if (log.isFatalEnabled()) { \ 319 log.log(log4cxx::Level::getFatal(), LOG4CXX_LOCATION, message); } \ 324 #define LOG_MESSAGE_VIA_STREAM_(logger, level, message) \ 325 std::ostringstream stream_; \ 326 stream_ << message; \ 327 logger.logMsg(level, LOG4CXX_LOCATION, stream_.str()) 343 #define LOGS(logger, level, message) \ 345 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 346 if (log.isEnabledFor(level)) { \ 347 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::toLevel(level), message); \ 362 #define LOGS_TRACE(message) \ 364 lsst::log::Log log; \ 365 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \ 366 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getTrace(), message); \ 381 #define LOGS_DEBUG(message) \ 383 lsst::log::Log log; \ 384 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \ 385 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getDebug(), message); \ 400 #define LOGS_INFO(message) \ 402 lsst::log::Log log; \ 403 if (log.isInfoEnabled()) { \ 404 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getInfo(), message); \ 419 #define LOGS_WARN(message) \ 421 lsst::log::Log log; \ 422 if (log.isWarnEnabled()) { \ 423 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getWarn(), message); \ 438 #define LOGS_ERROR(message) \ 440 lsst::log::Log log; \ 441 if (log.isErrorEnabled()) { \ 442 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getError(), message); \ 457 #define LOGS_FATAL(message) \ 459 lsst::log::Log log; \ 460 if (log.isFatalEnabled()) { \ 461 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getFatal(), message); \ 473 #define LOGL_TRACE(logger, message...) \ 475 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 476 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \ 477 log.log(log4cxx::Level::getTrace(), LOG4CXX_LOCATION, message);\ 489 #define LOGL_DEBUG(logger, message...) \ 491 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 492 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \ 493 log.log(log4cxx::Level::getDebug(), LOG4CXX_LOCATION, message); \ 505 #define LOGL_INFO(logger, message...) \ 507 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 508 if (log.isInfoEnabled()) { \ 509 log.log(log4cxx::Level::getInfo(), LOG4CXX_LOCATION, message); \ 521 #define LOGL_WARN(logger, message...) \ 523 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 524 if (log.isWarnEnabled()) { \ 525 log.log(log4cxx::Level::getWarn(), LOG4CXX_LOCATION, message); \ 537 #define LOGL_ERROR(logger, message...) \ 539 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 540 if (log.isErrorEnabled()) { \ 541 log.log(log4cxx::Level::getError(), LOG4CXX_LOCATION, message); \ 553 #define LOGL_FATAL(logger, message...) \ 555 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 556 if (log.isFatalEnabled()) { \ 557 log.log(log4cxx::Level::getFatal(), LOG4CXX_LOCATION, message); \ 573 #define LOGLS_TRACE(logger, message) \ 575 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 576 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \ 577 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getTrace(), message); \ 593 #define LOGLS_DEBUG(logger, message) \ 595 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 596 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \ 597 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getDebug(), message); \ 613 #define LOGLS_INFO(logger, message) \ 615 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 616 if (log.isInfoEnabled()) { \ 617 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getInfo(), message); \ 633 #define LOGLS_WARN(logger, message) \ 635 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 636 if (log.isWarnEnabled()) { \ 637 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getWarn(), message); \ 653 #define LOGLS_ERROR(logger, message) \ 655 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 656 if (log.isErrorEnabled()) { \ 657 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getError(), message); \ 673 #define LOGLS_FATAL(logger, message) \ 675 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \ 676 if (log.isFatalEnabled()) { \ 677 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getFatal(), message); \ 681 #define LOG_LVL_TRACE static_cast<int>(log4cxx::Level::TRACE_INT) 682 #define LOG_LVL_DEBUG static_cast<int>(log4cxx::Level::DEBUG_INT) 683 #define LOG_LVL_INFO static_cast<int>(log4cxx::Level::INFO_INT) 684 #define LOG_LVL_WARN static_cast<int>(log4cxx::Level::WARN_INT) 685 #define LOG_LVL_ERROR static_cast<int>(log4cxx::Level::ERROR_INT) 686 #define LOG_LVL_FATAL static_cast<int>(log4cxx::Level::FATAL_INT) 688 #define LOG_LOGGER lsst::log::Log 704 Log() : _logger(_defaultLogger()) { }
752 void log(log4cxx::LevelPtr level,
753 log4cxx::spi::LocationInfo
const& location,
754 char const* fmt, ...);
755 void logMsg(log4cxx::LevelPtr level,
756 log4cxx::spi::LocationInfo
const& location,
767 static log4cxx::LoggerPtr
const& _defaultLogger();
777 log4cxx::LoggerPtr _logger;
791 #endif // LSST_LOG_LOG_H static Log getDefaultLogger()
Return default logger instance, same as default constructor.
bool isWarnEnabled() const
Check whether the logger is enabled for the WARN Level.
bool isErrorEnabled() const
Check whether the logger is enabled for the ERROR Level.
static void configure()
Explicitly configures log4cxx and initializes logging system.
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.
Log getChild(std::string const &suffix) const
Return a logger which is a descendant to this logger.
This static class includes a variety of methods for interacting with the the logging module...
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...
bool isInfoEnabled() const
Check whether the logger is enabled for the INFO Level.
static void MDC(std::string const &key, std::string const &value)
Places a KEY/VALUE pair in the Mapped Diagnostic Context (MDC) for the current thread.
bool isDebugEnabled() const
Check whether the logger is enabled for the DEBUG Level.
std::string getName() const
Get the logger name associated with the Log object.
A base class for image defects.
static void MDCRemove(std::string const &key)
Remove the value associated with KEY within the MDC.
int getLevel() const
Retrieve the logging threshold.
void setLevel(int level)
Set the logging threshold to LEVEL.
bool isTraceEnabled() const
Check whether the logger is enabled for the TRACE Level.
bool isEnabledFor(int level) const
Return whether the logging threshold of the logger is less than or equal to LEVEL.
static Log getLogger(Log const &logger)
unsigned lwpID()
Function which returns LWP ID on platforms which support it.
static void configure_prop(std::string const &properties)
Configures log4cxx using a string containing the list of properties, equivalent to configuring from a...
bool isFatalEnabled() const
Check whether the logger is enabled for the FATAL Level.
static int MDCRegisterInit(std::function< void()> function)