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

#include <ball_recordstringformatter.h>

Detailed Description

This class provides a value-semantic log record formatter that holds a printf-style format specification and a timestamp offset. The overloaded operator() provided by the class formats a given record according to the format specification and outputs the formatted result to a given stream. The timestamp offset of the record formatter is added to each timestamp that is output to the stream.

See ball_recordstringformatter

Public Types

typedef bsl::allocator< char > allocator_type
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (RecordStringFormatter, bslma::UsesBslmaAllocator)
 
 RecordStringFormatter (const allocator_type &allocator=allocator_type())
 
 RecordStringFormatter (bslma::Allocator *basicallocator)
 
 RecordStringFormatter (const char *format, const allocator_type &allocator=allocator_type())
 
 RecordStringFormatter (const char *format, bslma::Allocator *basicAllocator)
 
 RecordStringFormatter (const bsl::string_view &format, const allocator_type &allocator=allocator_type())
 
 RecordStringFormatter (const bdlt::DatetimeInterval &offset, const allocator_type &allocator=allocator_type())
 
 RecordStringFormatter (bool publishInLocalTime, const allocator_type &allocator=allocator_type())
 
 RecordStringFormatter (const char *format, const bdlt::DatetimeInterval &offset, const allocator_type &allocator=allocator_type())
 
 RecordStringFormatter (const char *format, bool publishInLocalTime, const allocator_type &allocator=allocator_type())
 
 RecordStringFormatter (const RecordStringFormatter &original, const allocator_type &allocator=allocator_type())
 
 ~RecordStringFormatter ()=default
 
RecordStringFormatteroperator= (const RecordStringFormatter &rhs)
 
void disablePublishInLocalTime ()
 
void enablePublishInLocalTime ()
 
void setFormat (const char *format)
 
void setTimestampOffset (const bdlt::DatetimeInterval &offset)
 
void operator() (bsl::ostream &stream, const Record &record) const
 
const char * format () const
 
bool isPublishInLocalTimeEnabled () const
 
const bdlt::DatetimeIntervaltimestampOffset () const
 
allocator_type get_allocator () const
 

Static Public Member Functions

static int loadTextSchemeFormatter (RecordFormatterFunctor::Type *output, const bsl::string_view &format, const RecordFormatterOptions &formatOptions)
 

Static Public Attributes

static const char * k_DEFAULT_FORMAT
 
static const char * k_BASIC_ATTRIBUTE_FORMAT
 

Member Typedef Documentation

◆ allocator_type

Constructor & Destructor Documentation

◆ RecordStringFormatter() [1/10]

ball::RecordStringFormatter::RecordStringFormatter ( const allocator_type allocator = allocator_type())
explicit

Create a record formatter having a default format specification and a timestamp offset of 0. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory. If basicAllocator is not supplied or 0, the currently installed default allocator is used. The default format specification is:

"\n%d %p:%t %s %f:%l %c %m %u\n"

◆ RecordStringFormatter() [2/10]

ball::RecordStringFormatter::RecordStringFormatter ( bslma::Allocator basicallocator)
explicit

◆ RecordStringFormatter() [3/10]

ball::RecordStringFormatter::RecordStringFormatter ( const char *  format,
const allocator_type allocator = allocator_type() 
)
explicit

Create a record formatter having the specified format specification and a timestamp offset of 0. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory. If basicAllocator is not supplied or 0, the currently installed default allocator is used.

◆ RecordStringFormatter() [4/10]

ball::RecordStringFormatter::RecordStringFormatter ( const char *  format,
bslma::Allocator basicAllocator 
)

◆ RecordStringFormatter() [5/10]

ball::RecordStringFormatter::RecordStringFormatter ( const bsl::string_view format,
const allocator_type allocator = allocator_type() 
)
explicit

◆ RecordStringFormatter() [6/10]

ball::RecordStringFormatter::RecordStringFormatter ( const bdlt::DatetimeInterval offset,
const allocator_type allocator = allocator_type() 
)
explicit

Create a record formatter having a default format specification and the specified timestamp offset. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used. The default format specification is:

"\n%d %p:%t %s %f:%l %c %m %u\n"
Deprecated:
Use a constructor taking publishInLocalTime instead.

◆ RecordStringFormatter() [7/10]

ball::RecordStringFormatter::RecordStringFormatter ( bool  publishInLocalTime,
const allocator_type allocator = allocator_type() 
)
explicit

Create a record formatter having a default format specification, and if the specified publishInLocalTime flag is true, format the timestamp of each logged record in the local time of the current task, and format the timestamp in UTC otherwise. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used. The default format specification is:

"\n%d %p:%t %s %f:%l %c %m %u\n"
Note
Note that local time offsets are calculated for the timestamp of each formatted record and so track transitions into and out of Daylight Saving Time.

◆ RecordStringFormatter() [8/10]

ball::RecordStringFormatter::RecordStringFormatter ( const char *  format,
const bdlt::DatetimeInterval offset,
const allocator_type allocator = allocator_type() 
)

Create a record formatter having the specified format specification and the specified timestamp offset. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used.

Deprecated:
Use a constructor taking publishInLocalTime instead.

◆ RecordStringFormatter() [9/10]

ball::RecordStringFormatter::RecordStringFormatter ( const char *  format,
bool  publishInLocalTime,
const allocator_type allocator = allocator_type() 
)

Create a record formatter having the specified format specification, and if the specified publishInLocalTime flag is true, format the timestamp of each log in the local time of the current task, and format the timestamp in UTC otherwise. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used.

Note
Note that local time offsets are calculated for the timestamp of each formatted record and so track transitions into and out of Daylight Saving Time.

◆ RecordStringFormatter() [10/10]

ball::RecordStringFormatter::RecordStringFormatter ( const RecordStringFormatter original,
const allocator_type allocator = allocator_type() 
)

Create a record formatter initialized to the value of the specified original record formatter. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used.

◆ ~RecordStringFormatter()

ball::RecordStringFormatter::~RecordStringFormatter ( )
default

Destroy this object.

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

ball::RecordStringFormatter::BSLMF_NESTED_TRAIT_DECLARATION ( RecordStringFormatter  ,
bslma::UsesBslmaAllocator   
)

◆ disablePublishInLocalTime()

void ball::RecordStringFormatter::disablePublishInLocalTime ( )

Disable adjust of the timestamp attribute of to the current local time by this file observer. This method has no effect if adjustment to the current local time is not enabled.

◆ enablePublishInLocalTime()

void ball::RecordStringFormatter::enablePublishInLocalTime ( )

Enable adjustment of the timestamp attribute to the current local time. This method has no effect if adjustment to the current local time is already enabled.

◆ format()

const char * ball::RecordStringFormatter::format ( ) const
inline

Return the format specification of this record formatter.

◆ get_allocator()

RecordStringFormatter::allocator_type ball::RecordStringFormatter::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.

◆ isPublishInLocalTimeEnabled()

bool ball::RecordStringFormatter::isPublishInLocalTimeEnabled ( ) const

Return true if this formatter adjusts the timestamp attribute to the current local time, and false otherwise.

◆ loadTextSchemeFormatter()

static int ball::RecordStringFormatter::loadTextSchemeFormatter ( RecordFormatterFunctor::Type output,
const bsl::string_view format,
const RecordFormatterOptions formatOptions 
)
static

This class method configures a formatter for the "text" scheme using the specified format and formatOptions and if successful loads it into the specified output and returns zero. In case configuration fails a non-zero value is returned and output is loaded with a string formatter of the default format configuration

"\n%d %p:%t %s %f:%l %c %m %u\n"

◆ operator()()

void ball::RecordStringFormatter::operator() ( bsl::ostream &  stream,
const Record record 
) const

Format the specified record according to the format specification of this record formatter and output the result to the specified stream. The timestamp offset of this record formatter is added to each timestamp that is output to stream.

◆ operator=()

RecordStringFormatter & ball::RecordStringFormatter::operator= ( const RecordStringFormatter rhs)

Assign to this record formatter the value of the specified rhs record formatter.

◆ setFormat()

void ball::RecordStringFormatter::setFormat ( const char *  format)
inline

Set the format specification of this record formatter to the specified format.

◆ setTimestampOffset()

void ball::RecordStringFormatter::setTimestampOffset ( const bdlt::DatetimeInterval offset)
inline

Set the timestamp offset of this record formatter to the specified offset.

Deprecated:
Use enablePublishInLocalTime instead.

◆ timestampOffset()

const bdlt::DatetimeInterval & ball::RecordStringFormatter::timestampOffset ( ) const
inline

Return a reference to the non-modifiable timestamp offset of this record formatter.

Deprecated:
Use isPublishInLocalTimeEnabled instead.

Member Data Documentation

◆ k_BASIC_ATTRIBUTE_FORMAT

const char* ball::RecordStringFormatter::k_BASIC_ATTRIBUTE_FORMAT
static

A simple standard record format that renders ball::Attribute values in the formatted output.

Note
Note that this format is recommended over the default format, k_DEFAULT_FORMAT, for most applications (the default format is currently maintained for backwards compatibility).

◆ k_DEFAULT_FORMAT

const char* ball::RecordStringFormatter::k_DEFAULT_FORMAT
static

The default log format specification used by RecordStringFormatter.


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