42#include <log4cxx/basicconfigurator.h>
43#include <log4cxx/consoleappender.h>
44#include <log4cxx/helpers/bytearrayinputstream.h>
45#include <log4cxx/patternlayout.h>
46#include <log4cxx/propertyconfigurator.h>
47#include <log4cxx/xml/domconfigurator.h>
55#define MAX_LOG_MSG_LEN 1024
60const char configEnv[] =
"LSST_LOG_CONFIG";
63const char layoutPattern[] =
"%c %p: %m%n";
76 if (dotpos != std::string::npos && filename.
compare(dotpos, std::string::npos,
".xml") == 0) {
96 if (
const char* env = getenv(::configEnv)) {
97 if (env[0] and access(env, R_OK) == 0) {
104 log4cxx::LogString pattern(layoutPattern);
105 log4cxx::LayoutPtr layout(
new log4cxx::PatternLayout(pattern));
106 log4cxx::AppenderPtr appender(
new log4cxx::ConsoleAppender(layout));
107 auto root = log4cxx::Logger::getRootLogger();
108 root->addAppender(appender);
116bool initialized =
false;
122log4cxx::LoggerPtr log4cxxInit() {
132 return log4cxx::Logger::getRootLogger();
143 pthread_key_create(&key,
nullptr);
160log4cxx::LoggerPtr
const& Log::_defaultLogger() {
163 static log4cxx::LoggerPtr _default(::log4cxxInit());
181 ::initialized =
true;
185 log4cxx::BasicConfigurator::resetConfiguration();
205 ::initialized =
true;
209 log4cxx::BasicConfigurator::resetConfiguration();
211 ::configFromFile(filename);
224 ::initialized =
true;
228 log4cxx::BasicConfigurator::resetConfiguration();
231 log4cxx::helpers::InputStreamPtr inStream(
new log4cxx::helpers::ByteArrayInputStream(
data));
232 log4cxx::helpers::Properties prop;
242 if (
name ==
"root") {
257 if (loggername.
empty()){
278 std::string const oldValue = log4cxx::MDC::get(key);
279 log4cxx::MDC::remove(key);
280 log4cxx::MDC::put(key, value);
289 log4cxx::MDC::remove(key);
301 ::mdcInitFunctions.push_back(
std::move(
function));
312 _logger->setLevel(log4cxx::Level::toLevel(level));
319 log4cxx::LevelPtr level = _logger->getLevel();
322 levelno = level->toInt();
331 log4cxx::LevelPtr level = _logger->getEffectiveLevel();
334 levelno = level->toInt();
346 if (_logger->isEnabledFor(log4cxx::Level::toLevel(level))) {
369 if (pos == std::string::npos) {
387 log4cxx::spi::LocationInfo
const& location,
395 logMsg(level, location, msg);
401 log4cxx::spi::LocationInfo
const& location,
407 void *
ptr = pthread_getspecific(::pthreadKey.key);
408 if (
ptr ==
nullptr) {
411 ptr =
static_cast<void*
>(&::pthreadKey);
412 pthread_setspecific(::pthreadKey.key,
ptr);
416 for (
auto& fun: mdcInitFunctions) {
422 _logger->forcedLog(level, msg, location);
table::Key< std::string > name
LSST DM logging module built on log4cxx.
This static class includes a variety of methods for interacting with the the logging module.
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.
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...
void setLevel(int level)
Set the logging threshold to 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.
T find_first_not_of(T... args)
T find_last_of(T... args)
def getLogger(loggername)
unsigned lwpID()
Function which returns LWP ID on platforms which support it.
A base class for image defects.