lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Logger::Logger Class Reference

Singleton logger (instance()) with a minimum level and a list of handlers; log() passes each record to every handler. More...

#include <Logger.hh>

Public Types

enum  LEVEL {
  DEBUG =0 , TRACE , INFO , WARNING ,
  ERROR , FATAL , NOLOG , LAST_LEVEL =NOLOG ,
  NUM_LEVELS =LAST_LEVEL+1
}
 Message levels; logging(sev) is true when sev >= the current level. More...
 

Public Member Functions

void logmsg (const LogStream &ss, const LEVEL &sev=DEBUG)
 Increment the record counter and print the counter (4 digits), the 3-letter level and the text of ss to stdout; for levels above INFO also print the source file and line.
 
void loggerInfo (std::ostream &out)
 Write the start timestamp, current level, log name and number of levels to out.
 
const std::string & tstampStart () const
 Return the timestamp taken when the logger was created (format Y-m-d H:M:S.
 
void setLogname (const std::string &logname)
 Set the logger name shown by loggerInfo().
 
void setLevel (const LEVEL &level)
 Set the minimum level used by logging().
 
bool logging (const LEVEL &sev)
 Return true if sev >= the current level.
 
const char * levelToName (const LEVEL &level)
 Return the 3-letter name of level (e.g.
 
LEVEL name_to_level (const std::string &name)
 Return the LEVEL for a full level name ("DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "FATAL" or "NOLOG"); throws std::out_of_range for any other string.
 
void log (const LogRecord &rec)
 Increment the record counter and pass rec to every handler.
 
const unsigned counter ()
 Return the number of records counted so far.
 
void setLogger (const LEVEL &level=DEBUG, const std::string &timefmt="%H:%M:%S.%f")
 Set the level and the time format of every handler's formatter.
 
void addHandler (LogHandler *handler)
 add a handler for the messages, takes ownership of the object
 
void setTimeFormat (const std::string &timefmt="%Y-%m-%d %H:%M:%S.%f")
 Set the time format of every handler's formatter (a strftime format in which f is replaced by milliseconds).
 

Static Public Member Functions

static Logger * instance ()
 Return the singleton, creating it on the first call (no locking).
 

Public Attributes

char * LEVELCN [NUM_LEVELS]
 Full level names ("DEBUG" ... "NOLOG"), filled by the constructor.
 
char * LEVELC3 [NUM_LEVELS]
 Three-letter level names ("DBG", "TRC", "INF", "WRN", "ERR", "FTL", "NLG"), returned by levelToName().
 
char LEVELC1 [NUM_LEVELS]
 One-letter level codes ('D', 'T', 'I', 'W', 'E', 'F', 'N').
 

Detailed Description

Singleton logger (instance()) with a minimum level and a list of handlers; log() passes each record to every handler.

The instance starts at level INFO with one LogHandlerStdStreams.

Member Enumeration Documentation

◆ LEVEL

Message levels; logging(sev) is true when sev >= the current level.

Note that DEBUG (0) is below TRACE (1).

Enumerator
DEBUG 

Value 0.

TRACE 

Value 1.

INFO 

Value 2.

WARNING 

Value 3.

ERROR 

Value 4.

FATAL 

Value 5.

NOLOG 

Value 6.

LAST_LEVEL 

Equal to NOLOG (6).

NUM_LEVELS 

Number of levels (7).

Member Function Documentation

◆ addHandler()

void Logger::Logger::addHandler ( LogHandler *  handler)
inline

add a handler for the messages, takes ownership of the object

◆ counter()

const unsigned Logger::Logger::counter ( )
inline

Return the number of records counted so far.

◆ instance()

static Logger * Logger::Logger::instance ( )
inlinestatic

Return the singleton, creating it on the first call (no locking).

◆ levelToName()

const char * Logger::Logger::levelToName ( const LEVEL &  level)

Return the 3-letter name of level (e.g.

"WRN").

◆ log()

void Logger::Logger::log ( const LogRecord &  rec)

Increment the record counter and pass rec to every handler.

◆ loggerInfo()

void Logger::Logger::loggerInfo ( std::ostream &  out)

Write the start timestamp, current level, log name and number of levels to out.

◆ logging()

bool Logger::Logger::logging ( const LEVEL &  sev)
inline

Return true if sev >= the current level.

◆ logmsg()

void Logger::Logger::logmsg ( const LogStream &  ss,
const LEVEL &  sev = DEBUG 
)

Increment the record counter and print the counter (4 digits), the 3-letter level and the text of ss to stdout; for levels above INFO also print the source file and line.

◆ name_to_level()

LEVEL Logger::Logger::name_to_level ( const std::string &  name)

Return the LEVEL for a full level name ("DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "FATAL" or "NOLOG"); throws std::out_of_range for any other string.

◆ setLevel()

void Logger::Logger::setLevel ( const LEVEL &  level)
inline

Set the minimum level used by logging().

◆ setLogger()

void Logger::Logger::setLogger ( const LEVEL &  level = DEBUG,
const std::string &  timefmt = "%H:%M:%S.%f" 
)

Set the level and the time format of every handler's formatter.

◆ setLogname()

void Logger::Logger::setLogname ( const std::string &  logname)
inline

Set the logger name shown by loggerInfo().

◆ setTimeFormat()

void Logger::Logger::setTimeFormat ( const std::string &  timefmt = "%Y-%m-%d %H:%M:%S.%f")

Set the time format of every handler's formatter (a strftime format in which f is replaced by milliseconds).

◆ tstampStart()

const std::string & Logger::Logger::tstampStart ( ) const
inline

Return the timestamp taken when the logger was created (format Y-m-d H:M:S.

f, f being milliseconds).

Member Data Documentation

◆ LEVELC1

char Logger::Logger::LEVELC1[NUM_LEVELS]

One-letter level codes ('D', 'T', 'I', 'W', 'E', 'F', 'N').

◆ LEVELC3

char* Logger::Logger::LEVELC3[NUM_LEVELS]

Three-letter level names ("DBG", "TRC", "INF", "WRN", "ERR", "FTL", "NLG"), returned by levelToName().

◆ LEVELCN

char* Logger::Logger::LEVELCN[NUM_LEVELS]

Full level names ("DEBUG" ... "NOLOG"), filled by the constructor.


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