Qore Logger Module Reference  0.1.1
Logger::Logger Class Reference

Implements main logger class whose instance will be used by user code when logging. More...

Inheritance diagram for Logger::Logger:

Public Member Methods

 addAppender (LoggerAppender appender)
 Adds an appender to the appender list. More...
 
 assertLog (bool assertion, string message)
 Performs logging of assertions. More...
 
 constructor (*string n_name)
 Creates the object. More...
 
 debug (string message)
 Logs a message object with the DEBUG level. More...
 
 debugVar (string var_name, auto value)
 Logs the variable name and value using DEBUG level. More...
 
*LoggerLevel decLevel ()
 Decrement logger level. More...
 
 error (string message)
 Logs a message object with the ERROR level. More...
 
 fatal (string message)
 Logs a message object with the FATAL level. More...
 
bool getAdditivity ()
 Returns the additivity flag.
 
list< LoggerAppendergetAppenders ()
 Returns the appender list. More...
 
*LoggerLevel getLevel (bool effective=True)
 Returns the logging level. More...
 
string getName ()
 Returns the logger name.
 
*Logger getParent ()
 Returns the parent logger, if any.
 
*LoggerLevel incLevel ()
 Increment logger level. More...
 
 info (string message)
 Logs a message object with the INFO level. More...
 
bool isDebugEnabled ()
 Checks whether this Logger is enabled for the DEBUG Level.
 
bool isEnabledFor (LoggerLevel level)
 Checks whether this Logger is enabled for a given Level passed as parameter. More...
 
bool isEnabledFor (int level)
 Checks whether this Logger is enabled for a given Level passed as parameter. More...
 
bool isEnabledFor (string level)
 Checks whether this Logger is enabled for a given Level passed as parameter. More...
 
bool isErrorEnabled ()
 Checks whether this Logger is enabled for the ERROR Level.
 
bool isFatalEnabled ()
 Checks whether this Logger is enabled for the FATAL Level.
 
bool isInfoEnabled ()
 Checks whether this Logger is enabled for the INFO Level.
 
bool isTraceEnabled ()
 Checks whether this Logger is enabled for the TRACE Level.
 
bool isWarnEnabled ()
 Checks whether this Logger is enabled for the WARN Level.
 
 log (LoggerLevel level, string message)
 Logs a message using the provided logging level. More...
 
 log (int level, string message)
 Logs a message using the provided logging level. More...
 
 log (string level, string message)
 Logs a message using the provided logging level. More...
 
 logArgs (LoggerLevel level, string message, *softlist< auto > args)
 Logs a message using the provided logging level and a single argument for any format string arguments. More...
 
 logArgs (int level, string message, *softlist< auto > args)
 Logs a message using the provided logging level and a single argument for any format string arguments. More...
 
 logArgs (string level, string message, *softlist< auto > args)
 Logs a message using the provided logging level and a single argument for any format string arguments. More...
 
 logEvent (LoggerEvent event)
 Logs an already prepared logging event object. More...
 
 removeAllAppenders ()
 Clears the appender list by removing all appenders.
 
 removeAppender (LoggerAppender appender)
 Removes the appender from the list. More...
 
 setAdditivity (bool enable)
 Sets the additivity flag; when additivity is active, events are passed to parent loggers. More...
 
 setLevel (*LoggerLevel level)
 Sets the logging level. More...
 
 setLevel (string level)
 Sets the logging level. More...
 
 setLevel (int level)
 Sets the logging level. More...
 
 setParent (*Logger value)
 Sets the parent logger. More...
 
 trace (string message)
 Logs a message object with the TRACE level. More...
 
 traceVar (string var_name, auto value)
 Logs the variable name and value using TRACE level. More...
 
 warn (string message)
 Logs a message object with the WARN level. More...
 

Private Member Methods

 callAppenders (LoggerEvent event)
 Forwards the given logging event to all linked appenders. More...
 
hash< CallStackInfo > getLocation ()
 Returns the call location where the log function was called from.
 

Private:Internal Member Methods

RWLock lock ()
 The lock to protect object manipulation.
 

Static Private:Internal Member Methods

static RWLock hierarchyLock ()
 The lock to protect access to parent/child hierarchy.
 

Private:Internal Attributes

bool additivity = True
 Logger additivity. If set to true then child loggers will inherit the appenders of their ancestors by default.
 
list< LoggerAppenderappenders
 A collection of appenders linked to this logger.
 
*LoggerLevel currentLevel
 The assigned Logger level. If NOTHING, the parent level is used.
 
string name
 The name of this Logger instance.
 
*Logger parent
 The parent logger. Unassigned if this is the root logger.
 

Detailed Description

Implements main logger class whose instance will be used by user code when logging.

The Logger object is provided to user code. When a log is triggered then message, arguments, current code position, time are appended into LoggerEvent event instance when the logging level is enabled. The event is passed to all registered appenders in the given Logger as well as in parents in the hierarchy when additivity is enabled.

Member Function Documentation

◆ addAppender()

Logger::Logger::addAppender ( LoggerAppender  appender)

Adds an appender to the appender list.

Parameters
appenderadd a new LoggerAppender
Exceptions
LOGGER-ERRORexception if appender is already in list

◆ assertLog()

Logger::Logger::assertLog ( bool  assertion,
string  message 
)

Performs logging of assertions.

If the assertion parameter is False, then the message is logged using the ERROR level.

See also
log()
Parameters
assertionthe boolean assertion value
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ callAppenders()

Logger::Logger::callAppenders ( LoggerEvent  event)
private

Forwards the given logging event to all linked appenders.

Parameters
eventthe event to forward

◆ constructor()

Logger::Logger::constructor ( *string  n_name)

Creates the object.

Parameters
n_namethe name of the object

◆ debug()

Logger::Logger::debug ( string  message)

Logs a message object with the DEBUG level.

See also
log()
Parameters
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ debugVar()

Logger::Logger::debugVar ( string  var_name,
auto  value 
)

Logs the variable name and value using DEBUG level.

See also
log()
Parameters
var_namethe variable name
valuethe value of the variable

◆ decLevel()

*LoggerLevel Logger::Logger::decLevel ( )

Decrement logger level.

Returns
current LoggerLevel

◆ error()

Logger::Logger::error ( string  message)

Logs a message object with the ERROR level.

See also
log()
Parameters
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ fatal()

Logger::Logger::fatal ( string  message)

Logs a message object with the FATAL level.

See also
log()
Parameters
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ getAppenders()

list<LoggerAppender> Logger::Logger::getAppenders ( )

Returns the appender list.

Note that the appender list may be manipulated in another thread as internal lock is released when list is returned

◆ getLevel()

*LoggerLevel Logger::Logger::getLevel ( bool  effective = True)

Returns the logging level.

Parameters
effectiveif False then get current level which can be NOTHING, if True then get level which might be inherited from parent, Default: True
Exceptions
LOGGER-ERRORif cannot get effective level from hierarchy

◆ incLevel()

*LoggerLevel Logger::Logger::incLevel ( )

Increment logger level.

Returns
current LoggerLevel

◆ info()

Logger::Logger::info ( string  message)

Logs a message object with the INFO level.

See also
log()
Parameters
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ isEnabledFor() [1/3]

bool Logger::Logger::isEnabledFor ( LoggerLevel  level)

Checks whether this Logger is enabled for a given Level passed as parameter.

Parameters
levelthe log level to check

◆ isEnabledFor() [2/3]

bool Logger::Logger::isEnabledFor ( int  level)

Checks whether this Logger is enabled for a given Level passed as parameter.

Parameters
levelthe log level to check

◆ isEnabledFor() [3/3]

bool Logger::Logger::isEnabledFor ( string  level)

Checks whether this Logger is enabled for a given Level passed as parameter.

Parameters
levelthe log level to check

◆ log() [1/3]

Logger::Logger::log ( LoggerLevel  level,
string  message 
)

Logs a message using the provided logging level.

Parameters
levelThe logging level.
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ log() [2/3]

Logger::Logger::log ( int  level,
string  message 
)

Logs a message using the provided logging level.

Parameters
levelthe logging level.
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ log() [3/3]

Logger::Logger::log ( string  level,
string  message 
)

Logs a message using the provided logging level.

Parameters
levelThe logging level.
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ logArgs() [1/3]

Logger::Logger::logArgs ( LoggerLevel  level,
string  message,
*softlist< auto >  args 
)

Logs a message using the provided logging level and a single argument for any format string arguments.

Parameters
levelThe logging level.
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.
argsany format string arguments to the log message

◆ logArgs() [2/3]

Logger::Logger::logArgs ( int  level,
string  message,
*softlist< auto >  args 
)

Logs a message using the provided logging level and a single argument for any format string arguments.

Parameters
levelthe logging level.
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ logArgs() [3/3]

Logger::Logger::logArgs ( string  level,
string  message,
*softlist< auto >  args 
)

Logs a message using the provided logging level and a single argument for any format string arguments.

Parameters
levelThe logging level.
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ logEvent()

Logger::Logger::logEvent ( LoggerEvent  event)

Logs an already prepared logging event object.

Parameters
eventthe event to log

◆ removeAppender()

Logger::Logger::removeAppender ( LoggerAppender  appender)

Removes the appender from the list.

Parameters
appenderthe appender to remove

◆ setAdditivity()

Logger::Logger::setAdditivity ( bool  enable)

Sets the additivity flag; when additivity is active, events are passed to parent loggers.

Parameters
enablethe additivity flag; when additivity is active, events are passed to parent loggers

◆ setLevel() [1/3]

Logger::Logger::setLevel ( *LoggerLevel  level)

Sets the logging level.

Parameters
levelif nothing then inherits level from parent

◆ setLevel() [2/3]

Logger::Logger::setLevel ( string  level)

Sets the logging level.

Parameters
levelthe logging level as a string

◆ setLevel() [3/3]

Logger::Logger::setLevel ( int  level)

Sets the logging level.

Parameters
levelthe logging level to set

◆ setParent()

Logger::Logger::setParent ( *Logger  value)

Sets the parent logger.

Parameters
valuethe parent logger
Exceptions
LOGGER-ERRORin case of circular reference

◆ trace()

Logger::Logger::trace ( string  message)

Logs a message object with the TRACE level.

See also
log()
Parameters
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.

◆ traceVar()

Logger::Logger::traceVar ( string  var_name,
auto  value 
)

Logs the variable name and value using TRACE level.

See also
log()
Parameters
var_namethe variable name
valuethe value of the variable

◆ warn()

Logger::Logger::warn ( string  message)

Logs a message object with the WARN level.

See also
log()
Parameters
messagea string to log used as a format string for vsprintf(). Optional arguments are passed to the LoggerEvent object. If the last parameter is an ExceptionInfo typed hash, then it is considered "throwable" information.