39 #include <log4cxx/basicconfigurator.h>
40 #include <log4cxx/consoleappender.h>
41 #include <log4cxx/helpers/bytearrayinputstream.h>
42 #include <log4cxx/logmanager.h>
43 #include <log4cxx/propertyconfigurator.h>
44 #include <log4cxx/simplelayout.h>
45 #include <log4cxx/xml/domconfigurator.h>
52 #define MAX_LOG_MSG_LEN 1024
58 const char configEnv[] =
"LSST_LOG_CONFIG";
72 if (
const char* env = getenv(::configEnv)) {
74 if (env[0] and access(env, R_OK) == 0) {
77 ::setenv(
"LOG4CXX_CONFIGURATION", env, 1);
88 bool initialized =
init();
121 log4cxx::BasicConfigurator::resetConfiguration();
124 if (
const char* env = getenv(::configEnv)) {
125 if (env[0] and access(env, R_OK) == 0) {
132 log4cxx::LoggerPtr rootLogger = log4cxx::Logger::getRootLogger();
133 if (rootLogger->getAllAppenders().size() == 0) {
140 size_t dotpos = filename.find_last_of(
".");
141 if (dotpos == std::string::npos) {
144 return filename.substr(dotpos, filename.size() - dotpos);
158 log4cxx::BasicConfigurator::resetConfiguration();
174 std::vector<unsigned char> data(properties.begin(), properties.end());
175 log4cxx::helpers::InputStreamPtr inStream(
new log4cxx::helpers::ByteArrayInputStream(data));
176 log4cxx::helpers::Properties prop;
187 if (name ==
"root") {
210 if (loggername.empty()){
213 return log4cxx::Logger::getLogger(loggername);
224 throw std::invalid_argument(
"lsst::log::Log::pushContext(): "
225 "empty context name is not allowed");
228 if (name.find(
'.') != std::string::npos) {
229 throw std::invalid_argument(
"lsst::log::Log::pushContext(): "
230 "multi-level contexts are not allowed: " + name);
235 if (newName ==
"root") {
266 void Log::MDC(std::string
const& key, std::string
const& value) {
267 log4cxx::MDC::put(key, value);
275 log4cxx::MDC::remove(key);
284 logger->setLevel(log4cxx::Level::toLevel(level));
302 log4cxx::LevelPtr level = logger->getLevel();
305 levelno = level->toInt();
327 if (logger->isEnabledFor(log4cxx::Level::toLevel(level))) {
346 log4cxx::LevelPtr level,
347 std::string
const& filename,
348 std::string
const& funcname,
355 logger->forcedLog(level, msg, log4cxx::spi::LocationInfo(filename.c_str(),
361 log4cxx::LevelPtr level,
362 std::string
const& filename,
363 std::string
const& funcname,
370 vlog(
getLogger(loggername), level, filename, funcname, lineno, fmt, args);
377 log4cxx::LevelPtr level,
378 std::string
const& filename,
379 std::string
const& funcname,
386 vlog(logger, level, filename, funcname, lineno, fmt, args);
static log4cxx::LoggerPtr defaultLogger
table::Key< std::string > name
static void configure(void)
static log4cxx::LoggerPtr getLogger(log4cxx::LoggerPtr logger)
static void pushContext(std::string const &name)
static std::string getDefaultLoggerName(void)
static void initLog(void)
static void vlog(log4cxx::LoggerPtr logger, log4cxx::LevelPtr level, std::string const &filename, std::string const &funcname, unsigned int lineno, char const *fmt, va_list args)
static int getLevel(log4cxx::LoggerPtr logger)
static void MDCRemove(std::string const &key)
static void MDC(std::string const &key, std::string const &value)
static bool isEnabledFor(log4cxx::LoggerPtr logger, int level)
static void popContext(void)
static void configure_prop(std::string const &properties)
static void log(std::string const &loggername, log4cxx::LevelPtr level, std::string const &filename, std::string const &funcname, unsigned int lineno, char const *fmt,...)
static void setLevel(log4cxx::LoggerPtr logger, int level)
std::string getFileExtension(std::string const &filename)