LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Static Public Member Functions | Static Public Attributes | List of all members
lsst.log::Log Class Reference

#include <Log.h>

Static Public Member Functions

static void initLog (void)
 
static void configure (void)
 
static void configure (std::string const &filename)
 
static void configure_prop (std::string const &properties)
 
static std::string getDefaultLoggerName (void)
 
static log4cxx::LoggerPtr getLogger (log4cxx::LoggerPtr logger)
 
static log4cxx::LoggerPtr getLogger (std::string const &loggername)
 
static void pushContext (std::string const &name)
 
static void popContext (void)
 
static void MDC (std::string const &key, std::string const &value)
 
static void MDCRemove (std::string const &key)
 
static void setLevel (log4cxx::LoggerPtr logger, int level)
 
static void setLevel (std::string const &loggername, int level)
 
static int getLevel (log4cxx::LoggerPtr logger)
 
static int getLevel (std::string const &loggername)
 
static bool isEnabledFor (log4cxx::LoggerPtr logger, int level)
 
static bool isEnabledFor (std::string const &loggername, int level)
 
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 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 log (log4cxx::LoggerPtr logger, log4cxx::LevelPtr level, std::string const &filename, std::string const &funcname, unsigned int lineno, char const *fmt,...)
 

Static Public Attributes

static log4cxx::LoggerPtr defaultLogger = log4cxx::Logger::getRootLogger()
 

Detailed Description

This static class includes a variety of methods for interacting with the the logging module. These methods are not meant for direct use. Rather, they are used by the LOG* macros and the SWIG interface declared in logInterface.h.

Definition at line 489 of file Log.h.

Member Function Documentation

void lsst.log::Log::configure ( void  )
static

Configures log4cxx and initializes logging system by invoking initLog(). Uses either default configuration or log4cxx basic configuration. Default configuration can be specified via environment variable LSST_LOG_CONFIG, if it is set and specifies existing file name then this file name is used for configuration. Otherwise log4cxx BasicConfigurator class is used to configure, which is hardwired to add to the root logger a ConsoleAppender. In this case, the output will be formatted using a PatternLayout set to the pattern "%-4r [%t] %-5p %c %x - %m%n".

Definition at line 119 of file Log.cc.

119  {
120  // TODO: does resetConfiguration() remove existing appenders?
121  log4cxx::BasicConfigurator::resetConfiguration();
122 
123  // if LSST_LOG_CONFIG is set then use that file
124  if (const char* env = getenv(::configEnv)) {
125  if (env[0] and access(env, R_OK) == 0) {
126  configure(env);
127  return;
128  }
129  }
130 
131  // Do basic configuration (only if not configured already?)
132  log4cxx::LoggerPtr rootLogger = log4cxx::Logger::getRootLogger();
133  if (rootLogger->getAllAppenders().size() == 0) {
135  }
136  initLog();
137 }
static void configure(void)
Definition: Log.cc:119
def configure
Definition: log.py:42
static void initLog(void)
Definition: Log.cc:104
void lsst.log::Log::configure ( std::string const &  filename)
static

Configures log4cxx using FILENAME and initializes logging module by invoking initLog(). If FILENAME ends with ".xml", it is passed to log4cxx::xml::DOMConfigurator::configure(). Otherwise, it assumed to be a log4j Java properties file and is passed to log4cxx::PropertyConfigurator::configure(). See http://logging.apache.org/log4cxx/usage.html for additional details.

Parameters
filenamePath to configuration file.

Definition at line 156 of file Log.cc.

156  {
157  // TODO: does resetConfiguration() remove existing appenders?
158  log4cxx::BasicConfigurator::resetConfiguration();
159  if (getFileExtension(filename).compare(".xml") == 0) {
161  } else {
163  }
164  initLog();
165 }
def configure
Definition: log.py:42
static void initLog(void)
Definition: Log.cc:104
std::string getFileExtension(std::string const &filename)
Definition: Log.cc:139
void lsst.log::Log::configure_prop ( std::string const &  properties)
static

Configures log4cxx using a string containing the list of properties, equivalent to configuring from a file containing the same content but without creating temporary files.

Parameters
propertiesCOnfiguration properties.

Definition at line 173 of file Log.cc.

173  {
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;
177  prop.load(inStream);
179  initLog();
180 }
def configure
Definition: log.py:42
static void initLog(void)
Definition: Log.cc:104
std::string lsst.log::Log::getDefaultLoggerName ( void  )
static

Get the current default logger name.

Returns
String containing the default logger name.

Definition at line 185 of file Log.cc.

185  {
186  std::string name = defaultLogger->getName();
187  if (name == "root") {
188  name.clear();
189  }
190  return name;
191 }
static log4cxx::LoggerPtr defaultLogger
Definition: Log.h:491
table::Key< std::string > name
Definition: ApCorrMap.cc:71
int lsst.log::Log::getLevel ( log4cxx::LoggerPtr  logger)
static

Retrieve the logging threshold for LOGGER.

Returns
int Indicating the logging threshold.
Parameters
loggerLogger with threshold to return.

Definition at line 301 of file Log.cc.

301  {
302  log4cxx::LevelPtr level = logger->getLevel();
303  int levelno = -1;
304  if (level != NULL) {
305  levelno = level->toInt();
306  }
307  return levelno;
308 }
int lsst.log::Log::getLevel ( std::string const &  loggername)
static

Retrieve the logging threshold for the logger name LOGGERNAME.

Returns
Int indicating the logging threshold.
Parameters
loggernameName of logger with threshold to return.

Definition at line 315 of file Log.cc.

315  {
316  return getLevel(getLogger(loggername));
317 }
static log4cxx::LoggerPtr getLogger(log4cxx::LoggerPtr logger)
Definition: Log.cc:199
static int getLevel(log4cxx::LoggerPtr logger)
Definition: Log.cc:301
log4cxx::LoggerPtr lsst.log::Log::getLogger ( log4cxx::LoggerPtr  logger)
static

This method exists solely to simplify the LOGF macro. It merely returns the argument LOGGER.

Returns
log4cxx::LoggerPtr passed in.
Parameters
loggerlog4cxx::LoggerPtr to return.

Definition at line 199 of file Log.cc.

199  {
200  return logger;
201 }
log4cxx::LoggerPtr lsst.log::Log::getLogger ( std::string const &  loggername)
static

Returns a pointer to the log4cxx logger object associated with LOGGERNAME.

Returns
log4cxx::LoggerPtr corresponding to LOGGERNAME.
Parameters
loggernameName of logger to return.

Definition at line 209 of file Log.cc.

209  {
210  if (loggername.empty()){
211  return defaultLogger;
212  } else {
213  return log4cxx::Logger::getLogger(loggername);
214  }
215 }
static log4cxx::LoggerPtr defaultLogger
Definition: Log.h:491
void lsst.log::Log::initLog ( void  )
static

Initializes logging module (e.g. default logger and logging context).

Definition at line 104 of file Log.cc.

104  {
105  // Default logger initially set to root logger
106  defaultLogger = log4cxx::Logger::getRootLogger();
107 }
static log4cxx::LoggerPtr defaultLogger
Definition: Log.h:491
bool lsst.log::Log::isEnabledFor ( log4cxx::LoggerPtr  logger,
int  level 
)
static

Return whether the logging threshold of LOGGER is less than or equal to LEVEL.

Returns
Bool indicating whether or not logger is enabled.
Parameters
loggerLogger being queried.
levelLogging threshold to check.

Definition at line 326 of file Log.cc.

326  {
327  if (logger->isEnabledFor(log4cxx::Level::toLevel(level))) {
328  return true;
329  } else {
330  return false;
331  }
332 }
bool lsst.log::Log::isEnabledFor ( std::string const &  loggername,
int  level 
)
static

Return whether the logging threshold of the logger named LOGGERNAME is less than or equal to LEVEL.

Returns
Bool indicating whether or not logger is enabled.
Parameters
loggernameName of logger being queried.
levelLogging threshold to check.

Definition at line 341 of file Log.cc.

341  {
342  return isEnabledFor(getLogger(loggername), level);
343 }
static log4cxx::LoggerPtr getLogger(log4cxx::LoggerPtr logger)
Definition: Log.cc:199
static bool isEnabledFor(log4cxx::LoggerPtr logger, int level)
Definition: Log.cc:326
void lsst.log::Log::log ( std::string const &  loggername,
log4cxx::LevelPtr  level,
std::string const &  filename,
std::string const &  funcname,
unsigned int  lineno,
char const *  fmt,
  ... 
)
static
Parameters
loggernamename of logger
levelmessage level
filenamesource filename
funcnamesource function name
linenosource line number
fmtmessage format string

Definition at line 360 of file Log.cc.

367  {
368  va_list args;
369  va_start(args, fmt);
370  vlog(getLogger(loggername), level, filename, funcname, lineno, fmt, args);
371 }
static log4cxx::LoggerPtr getLogger(log4cxx::LoggerPtr logger)
Definition: Log.cc:199
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)
Definition: Log.cc:345
void lsst.log::Log::log ( log4cxx::LoggerPtr  logger,
log4cxx::LevelPtr  level,
std::string const &  filename,
std::string const &  funcname,
unsigned int  lineno,
char const *  fmt,
  ... 
)
static

Method used by LOG_INFO and similar macros to process a log message with variable arguments along with associated metadata.

Parameters
loggerthe logger
levelmessage level
filenamesource filename
funcnamesource function name
linenosource line number
fmtmessage format string

Definition at line 376 of file Log.cc.

383  {
384  va_list args;
385  va_start(args, fmt);
386  vlog(logger, level, filename, funcname, lineno, fmt, args);
387 }
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)
Definition: Log.cc:345
void lsst.log::Log::MDC ( std::string const &  key,
std::string const &  value 
)
static

Places a KEY/VALUE pair in the Mapped Diagnostic Context (MDC) for the current thread. The VALUE may then be included in log messages by using the following the X conversion character within a pattern layout as X{KEY}.

Parameters
keyUnique key.
valueString value.

Definition at line 266 of file Log.cc.

266  {
267  log4cxx::MDC::put(key, value);
268 }
void lsst.log::Log::MDCRemove ( std::string const &  key)
static

Remove the value associated with KEY within the MDC.

Parameters
keyKey identifying value to remove.

Definition at line 274 of file Log.cc.

274  {
275  log4cxx::MDC::remove(key);
276 }
void lsst.log::Log::popContext ( void  )
static

Pops the last pushed name off the global hierarchical default logger name.

Definition at line 248 of file Log.cc.

248  {
249  // switch to parent logger, this assumes that loggers are not
250  // re-parented between calls to push and pop
251  log4cxx::LoggerPtr parent = defaultLogger->getParent();
252  // root logger does not have parent, stay at root instead
253  if (parent) {
254  defaultLogger = parent;
255  }
256 }
static log4cxx::LoggerPtr defaultLogger
Definition: Log.h:491
void lsst.log::Log::pushContext ( std::string const &  name)
static

Pushes NAME onto the global hierarchical default logger name.

Parameters
nameString to push onto logging context.

Definition at line 221 of file Log.cc.

221  {
222  // can't handle empty names
223  if (name.empty()) {
224  throw std::invalid_argument("lsst::log::Log::pushContext(): "
225  "empty context name is not allowed");
226  }
227  // we do not allow multi-level context (logger1.logger2)
228  if (name.find('.') != std::string::npos) {
229  throw std::invalid_argument("lsst::log::Log::pushContext(): "
230  "multi-level contexts are not allowed: " + name);
231  }
232 
233  // Construct new default logger name
234  std::string newName = defaultLogger->getName();
235  if (newName == "root") {
236  newName = name;
237  } else {
238  newName += ".";
239  newName += name;
240  }
241  // Update defaultLogger
242  defaultLogger = log4cxx::Logger::getLogger(newName);
243 }
static log4cxx::LoggerPtr defaultLogger
Definition: Log.h:491
table::Key< std::string > name
Definition: ApCorrMap.cc:71
void lsst.log::Log::setLevel ( log4cxx::LoggerPtr  logger,
int  level 
)
static

Set the logging threshold for LOGGER to LEVEL.

Parameters
loggerLogger with threshold to adjust.
levelNew logging threshold.

Definition at line 283 of file Log.cc.

283  {
284  logger->setLevel(log4cxx::Level::toLevel(level));
285 }
void lsst.log::Log::setLevel ( std::string const &  loggername,
int  level 
)
static

Set the logging threshold for the logger named LOGGERNAME to LEVEL.

Parameters
loggernameName of logger with threshold to adjust.
levelNew logging threshold.

Definition at line 292 of file Log.cc.

292  {
293  setLevel(getLogger(loggername), level);
294 }
static log4cxx::LoggerPtr getLogger(log4cxx::LoggerPtr logger)
Definition: Log.cc:199
static void setLevel(log4cxx::LoggerPtr logger, int level)
Definition: Log.cc:283
void lsst.log::Log::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
Parameters
loggerthe logger
levelmessage level
filenamesource filename
funcnamesource function name
linenosource line number
fmtmessage format string
argsmessage arguments

Definition at line 345 of file Log.cc.

352  {
353  char msg[MAX_LOG_MSG_LEN];
354  vsnprintf(msg, MAX_LOG_MSG_LEN, fmt, args);
355  logger->forcedLog(level, msg, log4cxx::spi::LocationInfo(filename.c_str(),
356  funcname.c_str(),
357  lineno));
358 }
#define MAX_LOG_MSG_LEN
Definition: Log.cc:52

Member Data Documentation

log4cxx::LoggerPtr lsst.log::Log::defaultLogger = log4cxx::Logger::getRootLogger()
static

Reference to the defaultLogger used by LOG* macros.

Definition at line 491 of file Log.h.


The documentation for this class was generated from the following files: