Vault  4.1
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
VLogAppender Class Reference

VLogAppender is an abstract base class that defines the API for writing output to a destination. More...

#include <vlogger.h>

Inheritance diagram for VLogAppender:
VCoutLogAppender VFileLogAppender VRollingFileLogAppender VSilentLogAppender VStringLogAppender VStringVectorLogAppender

List of all members.

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 VStringgetName () 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

Detailed Description

VLogAppender is an abstract base class that defines the API for writing output to a destination.

Definition at line 247 of file vlogger.h.


Constructor & Destructor Documentation

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.

Parameters:
namethe name of this appender
formatOutputtrue if the logger should normally format its output, false for raw output
formatSpecthe format specifier for this appender's formatted output; empty for default
timeFormatfor any $localtime or $utctime elements in the formatSpec, the time format to use (
See also:
VInstantFormatter for definition); empty for default

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.

Parameters:
settingssettings containing appender "name" and optional "format-output" flag
defaultsoptional default settings for the appender to use if not specified in settings

Definition at line 929 of file vlogger.cpp.


Member Function Documentation

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

Returns the appender name.

Returns:
obvious

Definition at line 273 of file vlogger.h.

References mName.

bool VLogAppender::isDefaultAppender ( ) const

Returns true if this appender is the default appender. Diagnostic only.

Returns:
obvious

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().

Parameters:
levelthe level at which the message is being logged, and has already been filtered
fileif not null, the __FILE__ value indicating the source file that emitted the message
lineif not 0, the __LINE__ value indicating the line number in the source file that emitted the message
emitMessageif true, the message param should be emitted with the appender's normal formatting (e.g., time stamp, log level)
messagethe message to emit if emitMessage is true
specifiedLoggerNameif not empty, the logger name supplied by the original caller
actualLoggerNameif not empty, the name of the logger that is actually calling us
emitRawLineif true, the rawLine param should be emitted as is
rawLinethe 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.

Parameters:
messagethe 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.

Parameters:
infoNodethe 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).

Parameters:
levelthe level at which the message is being logged, and has already been filtered
fileif not null, the __FILE__ value indicating the source file that emitted the message
lineif not 0, the __LINE__ value indicating the line number in the source file that emitted the message
messagethe message to format and then emit to output
specifiedLoggerNameif not empty, the logger name supplied by the original caller
actualLoggerNameif 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.)

Parameters:
levelthe level at which the message is being logged, and has already been filtered
fileif not null, the __FILE__ value indicating the source file that emitted the message
lineif not 0, the __LINE__ value indicating the line number in the source file that emitted the message
messagethe message to format
specifiedLoggerNameif not empty, the logger name supplied by the original caller
actualLoggerNameif not empty, the name of the logger that is actually calling us
Returns:
the formatted message string

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.

Parameters:
linethe actual line to be emitted as is (it has already been formatted if that was needed)

Reimplemented in VStringVectorLogAppender, VStringLogAppender, VRollingFileLogAppender, VFileLogAppender, and VCoutLogAppender.

Definition at line 350 of file vlogger.h.


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.