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
60 const char configEnv[] =
"LSST_LOG_CONFIG";
63 const char layoutPattern[] =
"%c %p: %m%n";
76 if (dotpos != std::string::npos && filename.
compare(dotpos, std::string::npos,
".xml") == 0) {
94 void defaultConfig() {
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);
116 bool initialized =
false;
122 log4cxx::LoggerPtr log4cxxInit() {
132 return log4cxx::Logger::getRootLogger();
143 pthread_key_create(&
key,
nullptr);
160 log4cxx::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()){
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();
334 if (_logger->isEnabledFor(log4cxx::Level::toLevel(level))) {
357 if (pos == std::string::npos) {
375 log4cxx::spi::LocationInfo
const& location,
383 logMsg(level, location, msg);
389 log4cxx::spi::LocationInfo
const& location,
395 void *
ptr = pthread_getspecific(::pthreadKey.key);
396 if (
ptr ==
nullptr) {
399 ptr =
static_cast<void*
>(&::pthreadKey);
400 pthread_setspecific(::pthreadKey.key,
ptr);
404 for (
auto& fun: mdcInitFunctions) {
410 _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.
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.