LSSTApplications
20.0.0
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
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()
174 #define LOG_CHECK_LVL(logger, level) \
175 lsst::log::Log::getLogger(logger).isEnabledFor(level)
183 #define LOG_CHECK_TRACE() \
184 LOG4CXX_UNLIKELY(lsst::log::Log::getDefaultLogger().isTraceEnabled())
192 #define LOG_CHECK_DEBUG() \
193 LOG4CXX_UNLIKELY(lsst::log::Log::getDefaultLogger().isDebugEnabled())
201 #define LOG_CHECK_INFO() \
202 lsst::log::Log::getDefaultLogger().isInfoEnabled()
210 #define LOG_CHECK_WARN() \
211 lsst::log::Log::getDefaultLogger().isWarnEnabled()
219 #define LOG_CHECK_ERROR() \
220 lsst::log::Log::getDefaultLogger().isErrorEnabled()
228 #define LOG_CHECK_FATAL() \
229 lsst::log::Log::getDefaultLogger().isFatalEnabled()
240 #define LOG(logger, level, message...) \
242 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
243 if (log.isEnabledFor(level)) { \
244 log.log(log4cxx::Level::toLevel(level), LOG4CXX_LOCATION, message); } \
255 #define LOG_TRACE(message...) \
257 lsst::log::Log log; \
258 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
259 log.log(log4cxx::Level::getTrace(), LOG4CXX_LOCATION, message); } \
270 #define LOG_DEBUG(message...) \
272 lsst::log::Log log; \
273 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
274 log.log(log4cxx::Level::getDebug(), LOG4CXX_LOCATION, message); } \
285 #define LOG_INFO(message...) \
287 lsst::log::Log log; \
288 if (log.isInfoEnabled()) { \
289 log.log(log4cxx::Level::getInfo(), LOG4CXX_LOCATION, message); } \
300 #define LOG_WARN(message...) \
302 lsst::log::Log log; \
303 if (log.isWarnEnabled()) { \
304 log.log(log4cxx::Level::getWarn(), LOG4CXX_LOCATION, message); } \
315 #define LOG_ERROR(message...) \
317 lsst::log::Log log; \
318 if (log.isErrorEnabled()) { \
319 log.log(log4cxx::Level::getError(), LOG4CXX_LOCATION, message); } \
330 #define LOG_FATAL(message...) \
332 lsst::log::Log log; \
333 if (log.isFatalEnabled()) { \
334 log.log(log4cxx::Level::getFatal(), LOG4CXX_LOCATION, message); } \
339 #define LOG_MESSAGE_VIA_STREAM_(logger, level, message) \
340 std::ostringstream stream_; \
341 stream_ << message; \
342 logger.logMsg(level, LOG4CXX_LOCATION, stream_.str())
358 #define LOGS(logger, level, message) \
360 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
361 if (log.isEnabledFor(level)) { \
362 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::toLevel(level), message); \
377 #define LOGS_TRACE(message) \
379 lsst::log::Log log; \
380 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
381 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getTrace(), message); \
396 #define LOGS_DEBUG(message) \
398 lsst::log::Log log; \
399 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
400 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getDebug(), message); \
415 #define LOGS_INFO(message) \
417 lsst::log::Log log; \
418 if (log.isInfoEnabled()) { \
419 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getInfo(), message); \
434 #define LOGS_WARN(message) \
436 lsst::log::Log log; \
437 if (log.isWarnEnabled()) { \
438 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getWarn(), message); \
453 #define LOGS_ERROR(message) \
455 lsst::log::Log log; \
456 if (log.isErrorEnabled()) { \
457 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getError(), message); \
472 #define LOGS_FATAL(message) \
474 lsst::log::Log log; \
475 if (log.isFatalEnabled()) { \
476 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getFatal(), message); \
488 #define LOGL_TRACE(logger, message...) \
490 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
491 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
492 log.log(log4cxx::Level::getTrace(), LOG4CXX_LOCATION, message);\
504 #define LOGL_DEBUG(logger, message...) \
506 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
507 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
508 log.log(log4cxx::Level::getDebug(), LOG4CXX_LOCATION, message); \
520 #define LOGL_INFO(logger, message...) \
522 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
523 if (log.isInfoEnabled()) { \
524 log.log(log4cxx::Level::getInfo(), LOG4CXX_LOCATION, message); \
536 #define LOGL_WARN(logger, message...) \
538 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
539 if (log.isWarnEnabled()) { \
540 log.log(log4cxx::Level::getWarn(), LOG4CXX_LOCATION, message); \
552 #define LOGL_ERROR(logger, message...) \
554 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
555 if (log.isErrorEnabled()) { \
556 log.log(log4cxx::Level::getError(), LOG4CXX_LOCATION, message); \
568 #define LOGL_FATAL(logger, message...) \
570 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
571 if (log.isFatalEnabled()) { \
572 log.log(log4cxx::Level::getFatal(), LOG4CXX_LOCATION, message); \
588 #define LOGLS_TRACE(logger, message) \
590 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
591 if (LOG4CXX_UNLIKELY(log.isTraceEnabled())) { \
592 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getTrace(), message); \
608 #define LOGLS_DEBUG(logger, message) \
610 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
611 if (LOG4CXX_UNLIKELY(log.isDebugEnabled())) { \
612 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getDebug(), message); \
628 #define LOGLS_INFO(logger, message) \
630 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
631 if (log.isInfoEnabled()) { \
632 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getInfo(), message); \
648 #define LOGLS_WARN(logger, message) \
650 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
651 if (log.isWarnEnabled()) { \
652 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getWarn(), message); \
668 #define LOGLS_ERROR(logger, message) \
670 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
671 if (log.isErrorEnabled()) { \
672 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getError(), message); \
688 #define LOGLS_FATAL(logger, message) \
690 lsst::log::Log log(lsst::log::Log::getLogger(logger)); \
691 if (log.isFatalEnabled()) { \
692 LOG_MESSAGE_VIA_STREAM_(log, log4cxx::Level::getFatal(), message); \
696 #define LOG_LVL_TRACE static_cast<int>(log4cxx::Level::TRACE_INT)
697 #define LOG_LVL_DEBUG static_cast<int>(log4cxx::Level::DEBUG_INT)
698 #define LOG_LVL_INFO static_cast<int>(log4cxx::Level::INFO_INT)
699 #define LOG_LVL_WARN static_cast<int>(log4cxx::Level::WARN_INT)
700 #define LOG_LVL_ERROR static_cast<int>(log4cxx::Level::ERROR_INT)
701 #define LOG_LVL_FATAL static_cast<int>(log4cxx::Level::FATAL_INT)
703 #define LOG_LOGGER lsst::log::Log
719 Log() : _logger(_defaultLogger()) { }
767 void log(log4cxx::LevelPtr level,
768 log4cxx::spi::LocationInfo
const& location,
769 char const* fmt, ...);
770 void logMsg(log4cxx::LevelPtr level,
771 log4cxx::spi::LocationInfo
const& location,
782 static log4cxx::LoggerPtr
const& _defaultLogger();
792 log4cxx::LoggerPtr _logger;
814 _oldValue =
other._oldValue;
819 if (not _key.
empty()) {
820 if (_oldValue.
empty()) {
827 _oldValue =
other._oldValue;
836 if (not _key.
empty()) {
837 if (_oldValue.
empty()) {
861 #endif // LSST_LOG_LOG_H
LogMDCScope(LogMDCScope &&other)
static void MDCRemove(std::string const &key)
Remove the value associated with KEY within the MDC.
int getLevel() const
Retrieve the logging threshold.
~LogMDCScope()
Destructor restores old key value in MDC.
bool isEnabledFor(int level) const
Return whether the logging threshold of the logger is less than or equal to LEVEL.
LogMDCScope & operator=(LogMDCScope const &)=delete
static Log getLogger(Log const &logger)
LogMDCScope & operator=(LogMDCScope &&other)
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.
static void configure_prop(std::string const &properties)
Configures log4cxx using a string containing the list of properties, equivalent to configuring from a...
bool isWarnEnabled() const
Check whether the logger is enabled for the WARN Level.
bool isTraceEnabled() const
Check whether the logger is enabled for the TRACE Level.
bool isFatalEnabled() const
Check whether the logger is enabled for the FATAL Level.
LogMDCScope(LogMDCScope const &)=delete
LogMDCScope(std::string const &key, std::string const &value)
Constructor adds KEY/VALUE pair to current thread MDC.
unsigned lwpID()
Function which returns LWP ID on platforms which support it.
ItemVariant const * other
static void configure()
Explicitly configures log4cxx and initializes logging system.
std::string getName() const
Get the logger name associated with the Log object.
static Log getDefaultLogger()
Return default logger instance, same as default constructor.
bool isDebugEnabled() const
Check whether the logger is enabled for the DEBUG Level.
A base class for image defects.
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...
static int MDCRegisterInit(std::function< void()> function)
bool isInfoEnabled() const
Check whether the logger is enabled for the INFO Level.
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.
This static class includes a variety of methods for interacting with the the logging module.
Log getChild(std::string const &suffix) const
Return a logger which is a descendant to this logger.
void setLevel(int level)
Set the logging threshold to LEVEL.
bool isErrorEnabled() const
Check whether the logger is enabled for the ERROR Level.