![]() |
Vault
4.1
|
VLogAppender is an abstract base class that defines the API for writing output to a destination. More...
#include <vlogger.h>
Public Member Functions | |
VLogAppender (const VString &name, bool formatOutput, const VString &formatSpec, const VString &timeFormat) | |
Constructs the appender with the specified name. | |
VLogAppender (const VSettingsNode &settings, const VSettingsNode &defaults) | |
Constructs the appender from settings. | |
const VString & | getName () const |
Returns the appender name. | |
bool | isDefaultAppender () const |
Returns true if this appender is the default appender. Diagnostic only. | |
virtual void | emit (int level, const char *file, int line, bool emitMessage, const VString &message, const VString &specifiedLoggerName, const VString &actualLoggerName, bool emitRawLine, const VString &rawLine) |
Entry point called by named loggers to cause an appender to append to its output. | |
void | emitRaw (const VString &message) |
This utility API is used to call emit with a raw message. | |
virtual void | addInfo (VBentoNode &infoNode) const |
For diagnostic purposes, adds the properties/state of this appender to the supplied Bento node. | |
Static Public Attributes | |
static const bool | DO_FORMAT_OUTPUT = true |
static const bool | DONT_FORMAT_OUTPUT = false |
Protected Member Functions | |
virtual void | _emitMessage (int level, const char *file, int line, const VString &message, const VString &specifiedLoggerName, const VString &actualLoggerName) |
Emits a message using the appender's normal formatting of log output. | |
virtual VString | _formatMessage (int level, const char *file, int line, const VString &message, const VString &specifiedLoggerName, const VString &actualLoggerName) |
Formats a message prior to output. | |
virtual void | _emitRawLine (const VString &) |
This is the method that most concrete appenders must implement in order to write a message (whether it is in raw form or has already been formatted) to the output medium. | |
Static Protected Member Functions | |
static bool | _getBooleanInitSetting (const VString &attributePath, const VSettingsNode &settings, const VSettingsNode &defaults, bool defaultValue) |
static int | _getIntInitSetting (const VString &attributePath, const VSettingsNode &settings, const VSettingsNode &defaults, int defaultValue) |
static VString | _getStringInitSetting (const VString &attributePath, const VSettingsNode &settings, const VSettingsNode &defaults, const VString &defaultValue) |
Protected Attributes | |
VMutex | mMutex |
A mutex to protect against multiple threads' messages from being intertwined;. | |
VString | mName |
The name of the appender, used for lookup by loggers. | |
bool | mFormatOutput |
True if this appender should format messages it is asked to emit. | |
VString | mFormatSpec |
If formatting, this defines the format. | |
VInstantFormatter | mTimeFormatter |
If formatting and time stamp is printed, this defines the format. See VInstantFormatter for specification. | |
bool | mFormatUsesLocalTime |
bool | mFormatUsesUTCTime |
bool | mFormatUsesLevel |
bool | mFormatUsesThread |
bool | mFormatUsesLocation |
bool | mFormatUsesSpecifiedLoggerName |
bool | mFormatUsesActualLoggerName |
VLogAppender is an abstract base class that defines the API for writing output to a destination.
VLogAppender::VLogAppender | ( | const VString & | name, |
bool | formatOutput, | ||
const VString & | formatSpec, | ||
const VString & | timeFormat | ||
) |
Constructs the appender with the specified name.
A VNamedLogger that refers to this appender by name will route its output (after level filtering) to this appender.
name | the name of this appender |
formatOutput | true if the logger should normally format its output, false for raw output |
formatSpec | the format specifier for this appender's formatted output; empty for default |
timeFormat | for any $localtime or $utctime elements in the formatSpec, the time format to use ( |
Definition at line 913 of file vlogger.cpp.
VLogAppender::VLogAppender | ( | const VSettingsNode & | settings, |
const VSettingsNode & | defaults | ||
) |
Constructs the appender from settings.
A VNamedLogger that refers to this appender by name will route its output (after level filtering) to this appender.
settings | settings containing appender "name" and optional "format-output" flag |
defaults | optional default settings for the appender to use if not specified in settings |
Definition at line 929 of file vlogger.cpp.
const VString& VLogAppender::getName | ( | ) | const [inline] |
bool VLogAppender::isDefaultAppender | ( | ) | const |
Returns true if this appender is the default appender. Diagnostic only.
Definition at line 981 of file vlogger.cpp.
void VLogAppender::emit | ( | int | level, |
const char * | file, | ||
int | line, | ||
bool | emitMessage, | ||
const VString & | message, | ||
const VString & | specifiedLoggerName, | ||
const VString & | actualLoggerName, | ||
bool | emitRawLine, | ||
const VString & | rawLine | ||
) | [virtual] |
Entry point called by named loggers to cause an appender to append to its output.
The level is not used for filtering, but rather as information that usually appears in an appender's output format. Aside from the level, filename, linenumber, we have two strings, either of which can be optional. This allows loggers to supply a normal message, or a header message followed by a raw line, or just a raw line, without having to do more complex locking or loops. You can see this in how VNamedLogger is able to use this API in a single place for multiple uses. It is possible for both emitMessage and emitRawLine to be true. Primarily the ability to emit a raw line is used when doing hex dump (VLOGGER_HEXDUMP) or stack trace logging, where there is one header message that needs normal log formatting, followed by additional lines that are effectively just continuations of that same message, on additional lines.
Concrete subclasses rarely need to override this method; they typically instead implement the protected method _emitRawLine().
level | the level at which the message is being logged, and has already been filtered |
file | if not null, the __FILE__ value indicating the source file that emitted the message |
line | if not 0, the __LINE__ value indicating the line number in the source file that emitted the message |
emitMessage | if true, the message param should be emitted with the appender's normal formatting (e.g., time stamp, log level) |
message | the message to emit if emitMessage is true |
specifiedLoggerName | if not empty, the logger name supplied by the original caller |
actualLoggerName | if not empty, the name of the logger that is actually calling us |
emitRawLine | if true, the rawLine param should be emitted as is |
rawLine | the raw line to message to emit if emitRawLine is true |
Definition at line 963 of file vlogger.cpp.
References _emitMessage(), _emitRawLine(), and mMutex.
void VLogAppender::emitRaw | ( | const VString & | message | ) |
This utility API is used to call emit with a raw message.
message | the message to be emitted in raw form |
Definition at line 977 of file vlogger.cpp.
References emit(), VString::EMPTY(), NULL, and VLoggerLevel::TRACE.
void VLogAppender::addInfo | ( | VBentoNode & | infoNode | ) | const [virtual] |
For diagnostic purposes, adds the properties/state of this appender to the supplied Bento node.
Concrete classes should call inherited and then add their type-specific info.
infoNode | the Bento node to which to add this appender's properties |
Reimplemented in VStringVectorLogAppender, VStringLogAppender, VSilentLogAppender, VRollingFileLogAppender, VFileLogAppender, and VCoutLogAppender.
Definition at line 948 of file vlogger.cpp.
References VBentoNode::addBool(), VBentoNode::addString(), isDefaultAppender(), mFormatOutput, mFormatSpec, mName, and mTimeFormatter.
void VLogAppender::_emitMessage | ( | int | level, |
const char * | file, | ||
int | line, | ||
const VString & | message, | ||
const VString & | specifiedLoggerName, | ||
const VString & | actualLoggerName | ||
) | [protected, virtual] |
Emits a message using the appender's normal formatting of log output.
The base class implementation calls this->_formatMessage() to format the message if mFormatOutput is set. Then it calls _emitRawLine() to emit the resulting string (formatted or not).
level | the level at which the message is being logged, and has already been filtered |
file | if not null, the __FILE__ value indicating the source file that emitted the message |
line | if not 0, the __LINE__ value indicating the line number in the source file that emitted the message |
message | the message to format and then emit to output |
specifiedLoggerName | if not empty, the logger name supplied by the original caller |
actualLoggerName | if not empty, the name of the logger that is actually calling us |
Definition at line 1000 of file vlogger.cpp.
References _emitRawLine(), _formatMessage(), and mFormatOutput.
VString VLogAppender::_formatMessage | ( | int | level, |
const char * | file, | ||
int | line, | ||
const VString & | message, | ||
const VString & | specifiedLoggerName, | ||
const VString & | actualLoggerName | ||
) | [protected, virtual] |
Formats a message prior to output.
If the standard formatting supplied here is not what is desired, an appender can override this method. If this appender has mFormatOutput turned off, then this function is simply not called by _emitMessage() in the first place. (todo: This looks like a further opportunity to use a factory pattern to install a custom formatter on any appender.)
level | the level at which the message is being logged, and has already been filtered |
file | if not null, the __FILE__ value indicating the source file that emitted the message |
line | if not 0, the __LINE__ value indicating the line number in the source file that emitted the message |
message | the message to format |
specifiedLoggerName | if not empty, the logger name supplied by the original caller |
actualLoggerName | if not empty, the name of the logger that is actually calling us |
Definition at line 1009 of file vlogger.cpp.
References VString::EMPTY(), VThread::getCurrentThreadName(), VInstant::getLocalString(), VLoggerLevel::getName(), VInstant::getSimulatedClockOffset(), VInstant::getUTCString(), VInstant::isTimeFrozen(), mFormatSpec, mTimeFormatter, NULL, VString::replace(), VInstant::setTrueNow(), and VDuration::ZERO().
virtual void VLogAppender::_emitRawLine | ( | const VString & | ) | [inline, protected, virtual] |
This is the method that most concrete appenders must implement in order to write a message (whether it is in raw form or has already been formatted) to the output medium.
The reason an emty implementation is provided here, rather than it being pure virtual, is that some appenders override _emitMessage() instead because they always bypass formatting.
line | the actual line to be emitted as is (it has already been formatted if that was needed) |
Reimplemented in VStringVectorLogAppender, VStringLogAppender, VRollingFileLogAppender, VFileLogAppender, and VCoutLogAppender.