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);