BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball::ObserverFormatterImp Class Reference

#include <ball_observerformatterimp.h>

Detailed Description

This class provides a common implementation of formatting-related methods for observer components that support scheme-based log record formatting. It manages a log record formatter, format configuration strings, and time zone preferences. This implementation is intended to be used as a data member in concrete observer classes to provide consistent formatting behavior across different observer types.

See ball_observerformatterimp

Public Types

typedef RecordFormatterFunctor::Type RecordFormatter
 
typedef bsl::allocator< char > allocator_type
 

Public Member Functions

 ObserverFormatterImp (const bsl::string_view &format, TimezoneEnum timezoneDefault, const allocator_type &allocator=allocator_type())
 
void setTimezoneDefault (TimezoneEnum timezoneDefault)
 
void setFormatFunctor (const RecordFormatter &formatter)
 
int setFormat (const bsl::string_view &format)
 
void formatLogRecord (bsl::ostream &stream, const bsl::shared_ptr< const Record > &record) const
 
const bsl::stringgetFormat () const
 
TimezoneEnum getTimezoneDefault () const
 
allocator_type get_allocator () const
 

Member Typedef Documentation

◆ allocator_type

◆ RecordFormatter

RecordFormatter is an alias for the type of the functor used for formatting log records to a stream.

Constructor & Destructor Documentation

◆ ObserverFormatterImp()

ball::ObserverFormatterImp::ObserverFormatterImp ( const bsl::string_view format,
TimezoneEnum  timezoneDefault,
const allocator_type allocator = allocator_type() 
)
inlineexplicit

Create a ObserverFormatterImp instance that formats log records using the specified format and timezoneDefault. It is strongly advised to specify UTC for timezoneDefault. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used.

Precondition
The behavior is undefined unless format is a valid format string (either one that starts with a scheme or a "text" scheme format).
Note
Note that not giving a valid default format string by the observer will result in no logging output if no valid format is set afterwards, so it is a serious error.

Member Function Documentation

◆ formatLogRecord()

void ball::ObserverFormatterImp::formatLogRecord ( bsl::ostream &  stream,
const bsl::shared_ptr< const Record > &  record 
) const
inline

Format the specified log record into the specified output stream using the current record formatter functor.

◆ get_allocator()

ObserverFormatterImp::allocator_type ball::ObserverFormatterImp::get_allocator ( ) const
inline

Return the allocator used by this object to supply memory.

Note
Note that if no allocator was supplied at construction the default allocator in effect at construction is used.

◆ getFormat()

const bsl::string & ball::ObserverFormatterImp::getFormat ( ) const
inline

Return the currently active format configuration string of this object.

◆ getTimezoneDefault()

ObserverFormatterImp::TimezoneEnum ball::ObserverFormatterImp::getTimezoneDefault ( ) const
inline

Return the currently active time zone default of this object.

◆ setFormat()

int ball::ObserverFormatterImp::setFormat ( const bsl::string_view format)
inline

Set the log record format specifications for this object according to the specified format. Return 0 on success, and a non-zero value otherwise. This method has no effect on format if format is not a valid format specification. If format does not start with a scheme (it has no "://" in it) use the default "text" scheme.

◆ setFormatFunctor()

void ball::ObserverFormatterImp::setFormatFunctor ( const RecordFormatter formatter)
inline

Set the formatting functor used when writing records to the specified formatter functor.

Note
Note that this method is not able to communicate the timezone default settings to the formatter, prefer setFormat.

◆ setTimezoneDefault()

void ball::ObserverFormatterImp::setTimezoneDefault ( TimezoneEnum  timezoneDefault)
inline

Set the default time zone used for timestamps that have no timezone preference specified in the format config string. This method recreates the formatter used with the new timezone setting and the last successfully-set format config string.

Note
Note that (at the time of writing) the printf-style format strings do not have syntax to specify the time zone so for such-configured formatters all timestamps will use this time zone default.

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