Vault  4.1
Public Member Functions | Protected Member Functions | Friends
VNamedLogger Class Reference

VNamedLogger defines an object to which log output is initially sent. More...

#include <vlogger.h>

Inheritance diagram for VNamedLogger:
VStringLogger VStringVectorLogger

List of all members.

Public Member Functions

 VNamedLogger (const VString &name, int level, const VStringVector &appenderNames, VLogAppenderPtr specificAppender=VLogAppenderPtr())
 Constructs a logger.
void clearAppenders ()
 Removes all appender names.
void setAppender (const VString &appenderName)
 Clears all appenders names and adds one specific name.
void addAppender (const VString &appenderName)
 Adds an appender name to the existing list.
void log (int level, const char *file, int line, const VString &message, const VString &specifiedLoggerName=VString::EMPTY())
 Logs a message (subject to filtering).
void log (int level, const VString &message)
 Logs a message (subject to filtering).
void logHexDump (int level, const VString &message, const VString &specifiedLoggerName, const Vu8 *buffer, Vs64 length)
 Logs a hex dump of the specified data (subject to filtering).
void emitStackCrawlLine (const VString &message)
 Emits a string in its raw form, without filtering; presumably called by a stack trace function.
const VStringgetName () const
 Returns the logger's name.
bool isEnabledFor (int level)
 Returns true if the logger's current level would allow the specified level to emit.
int getLevel () const
 Returns the logger's current level.
void setLevel (int level)
 Sets the logger's level.
void setRepetitionFilterEnabled (bool enabled)
 Enabled or disables repetition filtering by this logger.
int getPrintStackLevel () const
 Returns the log level at which the logger will cause a stack trace to be emitted along with the logged message.
void setPrintStackInfo (int printStackLevel, int maxNumOccurrences, const VDuration &timeLimit)
 Configures the stack trace printing for this logger.
bool isDefaultLogger () const
 Returns true if this logger is currently the default logger.
virtual void addInfo (VBentoNode &infoNode) const
 For diagnostic purposes, adds the properties/state of this logger to the supplied Bento node.

Protected Member Functions

virtual void _emitToAppenders (int level, const char *file, int line, bool emitMessage, const VString &message, const VString &specifiedLoggerName, bool emitRawLine, const VString &rawLine)
 Emits the specified message and/or raw line to all appenders appropriate to this logger (see class-level doc for VNamedLogger).

Friends

class VLoggerRepetitionFilter
class VLoggerPrintStackConfig

Detailed Description

VNamedLogger defines an object to which log output is initially sent.

A logger has a name (that is used to locate it and direct output to it) and a level (which the logger uses to filter what it receives). After filtering its input by log level and possibly by the use of a repetition filter, a logger emits a message that has passed the level and repetition filters, to zero or more appenders, as follows:

Definition at line 509 of file vlogger.h.


Constructor & Destructor Documentation

VNamedLogger::VNamedLogger ( const VString name,
int  level,
const VStringVector appenderNames,
VLogAppenderPtr  specificAppender = VLogAppenderPtr() 
)

Constructs a logger.

If neither any appender names nor a specific appender is supplied here, the logger will be initialized with 1 appender name that is empty, which in turn causes it to emit to the default logger. (It will also emit to all "global appenders".) The appenders names can also be cleared, updated, or set later.

Parameters:
namea name for the logger, used to find it if it is logged to by name
levelthe level above which log output is filtered; for example, a logger at level INFO will not emit DEBUG messages
appenderNamesan optional list of appender names to which filtered output will be emitted (see note above)
specificAppenderan optional specific appender instance to which filtered output will be emitted (see note above)

Definition at line 28 of file vlogger.cpp.

References VString::EMPTY().


Member Function Documentation

void VNamedLogger::setAppender ( const VString appenderName)

Clears all appenders names and adds one specific name.

Parameters:
appenderNamethe appender name to set

Definition at line 49 of file vlogger.cpp.

void VNamedLogger::addAppender ( const VString appenderName)

Adds an appender name to the existing list.

Parameters:
appenderNamethe appender name to add

Definition at line 54 of file vlogger.cpp.

void VNamedLogger::log ( int  level,
const char *  file,
int  line,
const VString message,
const VString specifiedLoggerName = VString::EMPTY() 
)

Logs a message (subject to filtering).

The file and line parameters may be formatted into the text that is actually logged by a particular appender, and that may depend on the log level.

Parameters:
levelthe level of the message
filethe source file name where the message was logged (from __FILE__ symbol)
linethe line in the source file where the message was logged (from __LINE__ symbol)
messagethe message to be logged
specifiedLoggerNameif not empty, the logger name supplied by caller

Definition at line 58 of file vlogger.cpp.

References _emitToAppenders(), VLoggerRepetitionFilter::checkMessage(), VLoggerRepetitionFilter::checkTimeout(), VString::EMPTY(), VLoggerRepetitionFilter::isEnabled(), VThread::logStackCrawl(), and VMutexLocker::unlock().

void VNamedLogger::log ( int  level,
const VString message 
)

Logs a message (subject to filtering).

Parameters:
levelthe level of the message
messagethe message to be logged

Definition at line 98 of file vlogger.cpp.

References log(), and NULL.

void VNamedLogger::logHexDump ( int  level,
const VString message,
const VString specifiedLoggerName,
const Vu8 buffer,
Vs64  length 
)

Logs a hex dump of the specified data (subject to filtering).

Parameters:
levelthe level of the message
messagethe message to be logged as the line of output preceding the hex data
specifiedLoggerNameif not empty, the logger name supplied by caller
buffera pointer to some data
lengththe number of bytes of the data that should be examined and written in hex form

Definition at line 102 of file vlogger.cpp.

References _emitToAppenders(), VString::copyFromBuffer(), VMemoryStream::getBuffer(), VMemoryStream::getEOFOffset(), NULL, and VHex::printHex().

void VNamedLogger::emitStackCrawlLine ( const VString message)

Emits a string in its raw form, without filtering; presumably called by a stack trace function.

Parameters:
messagethe string to be logged

Definition at line 126 of file vlogger.cpp.

References _emitToAppenders(), VString::EMPTY(), NULL, and VLoggerLevel::TRACE.

const VString& VNamedLogger::getName ( ) const [inline]

Returns the logger's name.

Returns:
obvious

Definition at line 573 of file vlogger.h.

bool VNamedLogger::isEnabledFor ( int  level) [inline]

Returns true if the logger's current level would allow the specified level to emit.

Parameters:
levelobvious
Returns:
obvious

Definition at line 574 of file vlogger.h.

int VNamedLogger::getLevel ( ) const [inline]

Returns the logger's current level.

Returns:
obvious

Definition at line 575 of file vlogger.h.

void VNamedLogger::setLevel ( int  level)

Sets the logger's level.

Parameters:
levelthe level above which messages are filtered

Definition at line 131 of file vlogger.cpp.

References VLogger::checkMaxActiveLogLevelForChangedLogger().

void VNamedLogger::setRepetitionFilterEnabled ( bool  enabled) [inline]

Enabled or disables repetition filtering by this logger.

Parameters:
enabledobvious

Definition at line 578 of file vlogger.h.

References VLoggerRepetitionFilter::setEnabled().

int VNamedLogger::getPrintStackLevel ( ) const [inline]

Returns the log level at which the logger will cause a stack trace to be emitted along with the logged message.

For example, if the print stack level is ERROR, then any log output at ERROR level or more severe (e.g. FATAL) will emit the message and also emit a stack trace.

Returns:
the current level that triggers a stack trace to be logged

Definition at line 586 of file vlogger.h.

References VLoggerPrintStackConfig::getLevel().

void VNamedLogger::setPrintStackInfo ( int  printStackLevel,
int  maxNumOccurrences,
const VDuration timeLimit 
) [inline]

Configures the stack trace printing for this logger.

Parameters:
printStackLevellog messages at this level or lower will also emit a stack trace
maxNumOccurrencesafter this many stack traces are emitted, further stack traces will not occur; 0 or -1 disables stack trace
timeLimitafter this amount of time elapses, further stack traces will not occur; VInstant::INFINITE_FUTURE() means no time limit

Definition at line 593 of file vlogger.h.

bool VNamedLogger::isDefaultLogger ( ) const

Returns true if this logger is currently the default logger.

Returns:
obvious

Definition at line 137 of file vlogger.cpp.

void VNamedLogger::addInfo ( VBentoNode infoNode) const [virtual]

For diagnostic purposes, adds the properties/state of this logger to the supplied Bento node.

Calls _addInfo which a subclass should override to change the type value. Subclasses should call inherited and then add their type-specific info.

Reimplemented in VStringVectorLogger, and VStringLogger.

Definition at line 80 of file vlogger.cpp.

References VBentoNode::addBool(), VBentoNode::addInt(), VBentoNode::addString(), VBentoNode::addStringArray(), VLoggerPrintStackConfig::getLevel(), isDefaultLogger(), and VLoggerRepetitionFilter::isEnabled().

void VNamedLogger::_emitToAppenders ( int  level,
const char *  file,
int  line,
bool  emitMessage,
const VString message,
const VString specifiedLoggerName,
bool  emitRawLine,
const VString rawLine 
) [protected, virtual]

Emits the specified message and/or raw line to all appenders appropriate to this logger (see class-level doc for VNamedLogger).

Parameters:
levelthe level of the message
filethe source file name where the message was logged (from __FILE__ symbol)
linethe line in the source file where the message was logged (from __LINE__ symbol)
emitMessagetrue if the message parameter is to be emitted
messagethe message to be emitted if emitMessage is true (the appenders typically format the message)
specifiedLoggerNameif not empty, the logger name supplied by caller
emitRawLinetrue if the rawLine parameter is to be emitted
rawLinethe raw line to be emitted if emitRawLine is true (the appenders should not format the raw line)

Reimplemented in VStringVectorLogger, and VStringLogger.

Definition at line 141 of file vlogger.cpp.

References VLogger::getAppender(), and VLogger::getDefaultAppender().


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.