![]() |
Vault
4.1
|
VNamedLogger defines an object to which log output is initially sent. More...
#include <vlogger.h>
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 VString & | getName () 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 |
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:
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.
name | a name for the logger, used to find it if it is logged to by name |
level | the level above which log output is filtered; for example, a logger at level INFO will not emit DEBUG messages |
appenderNames | an optional list of appender names to which filtered output will be emitted (see note above) |
specificAppender | an 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().
void VNamedLogger::setAppender | ( | const VString & | appenderName | ) |
Clears all appenders names and adds one specific name.
appenderName | the 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.
appenderName | the 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.
level | the level of the message |
file | the source file name where the message was logged (from __FILE__ symbol) |
line | the line in the source file where the message was logged (from __LINE__ symbol) |
message | the message to be logged |
specifiedLoggerName | if 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).
level | the level of the message |
message | the message to be logged |
Definition at line 98 of file vlogger.cpp.
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).
level | the level of the message |
message | the message to be logged as the line of output preceding the hex data |
specifiedLoggerName | if not empty, the logger name supplied by caller |
buffer | a pointer to some data |
length | the 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.
message | the 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] |
bool VNamedLogger::isEnabledFor | ( | int | level | ) | [inline] |
int VNamedLogger::getLevel | ( | ) | const [inline] |
void VNamedLogger::setLevel | ( | int | level | ) |
Sets the logger's level.
level | the 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.
enabled | obvious |
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.
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.
printStackLevel | log messages at this level or lower will also emit a stack trace |
maxNumOccurrences | after this many stack traces are emitted, further stack traces will not occur; 0 or -1 disables stack trace |
timeLimit | after this amount of time elapses, further stack traces will not occur; VInstant::INFINITE_FUTURE() means no time limit |
bool VNamedLogger::isDefaultLogger | ( | ) | const |
Returns true if this logger is currently the default logger.
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).
level | the level of the message |
file | the source file name where the message was logged (from __FILE__ symbol) |
line | the line in the source file where the message was logged (from __LINE__ symbol) |
emitMessage | true if the message parameter is to be emitted |
message | the message to be emitted if emitMessage is true (the appenders typically format the message) |
specifiedLoggerName | if not empty, the logger name supplied by caller |
emitRawLine | true if the rawLine parameter is to be emitted |
rawLine | the 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().