BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball::RecordJsonFormatter Class Reference

#include <ball_recordjsonformatter.h>

Public Types

typedef bsl::vector< RecordJsonFormatter_FieldFormatter * > FieldFormatters
 
typedef bsl::allocator allocator_type
 

Public Member Functions

 RecordJsonFormatter (const allocator_type &allocator=allocator_type())
 
 RecordJsonFormatter (const RecordJsonFormatter &original, const allocator_type &allocator=allocator_type())
 
 RecordJsonFormatter (bslmf::MovableRef< RecordJsonFormatter > original) BSLS_KEYWORD_NOEXCEPT
 
 RecordJsonFormatter (bslmf::MovableRef< RecordJsonFormatter > original, const allocator_type &allocator)
 
 ~RecordJsonFormatter ()
 Destroy this object.
 
RecordJsonFormatteroperator= (const RecordJsonFormatter &rhs)
 
RecordJsonFormatteroperator= (bslmf::MovableRef< RecordJsonFormatter > rhs)
 
int setFormat (const bsl::string_view &format)
 
void setRecordSeparator (const bsl::string_view &recordSeparator)
 
void operator() (bsl::ostream &stream, const Record &record) const
 
const bsl::stringformat () const
 
const bsl::stringrecordSeparator () const
 Return the record separator of this record JSON formatter.
 
BSLS_DEPRECATE bslma::Allocatorallocator () const
 
allocator_type get_allocator () const
 Return the allocator used by this object to supply memory.
 

Detailed Description

This class provides a function object that formats a log record as JSON text elements and renders them to an output stream. The overloaded operator() provided by the class formats log record according to JSON message format specification supplied at construction (either by the setFormat manipulator or by default) and outputs the result to the stream. This functor type is designed to match the function signature expected by many concrete ball::Observer implementations that publish log records (for example, see ball::FileObserver2::setLogFileFunctor).

See ball_recordjsonformatter

Member Typedef Documentation

◆ allocator_type

◆ FieldFormatters

typedef bsl::vector<RecordJsonFormatter_FieldFormatter*> ball::RecordJsonFormatter::FieldFormatters

FieldFormatters is an alias for a vector of the RecordJsonFormatter_FieldFormatter objects, each of which is initialized from the format specification and responsible for rendering one field of a ball::Record to the output JSON stream.

Constructor & Destructor Documentation

◆ RecordJsonFormatter() [1/4]

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

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

["timestamp", "processId", "threadId", "severity", "file", "line",
"category", "message", "attributes"]

The default record separator is "\n".

◆ RecordJsonFormatter() [2/4]

ball::RecordJsonFormatter::RecordJsonFormatter ( const RecordJsonFormatter original,
const allocator_type allocator = allocator_type() 
)
inline

Create a record JSON 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.

◆ RecordJsonFormatter() [3/4]

ball::RecordJsonFormatter::RecordJsonFormatter ( bslmf::MovableRef< RecordJsonFormatter original)
inline

Create a record JSON formatter having the same format specification and record separator as in the specified original formatter, and adopting all outstanding memory allocations and the allocator associated with the original formatter. original is left in a valid but unspecified state.

◆ RecordJsonFormatter() [4/4]

ball::RecordJsonFormatter::RecordJsonFormatter ( bslmf::MovableRef< RecordJsonFormatter original,
const allocator_type allocator 
)
inline

Create a record JSON formatter, having the same format specification and record separator as in the specified original formatter. The format specification of original is moved to the new object, and all outstanding memory allocations and the specified allocator are adopted if allocator == original.get_allocator(). original is left in a valid but unspecified state.

◆ ~RecordJsonFormatter()

ball::RecordJsonFormatter::~RecordJsonFormatter ( )

Member Function Documentation

◆ allocator()

bslma::Allocator * ball::RecordJsonFormatter::allocator ( ) const
inline
Deprecated:
Use .mechanism() instead.

◆ format()

const bsl::string & ball::RecordJsonFormatter::format ( ) const
inline

Return the message format specification of this record JSON formatter. See {Record Format Specification}.

◆ get_allocator()

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

◆ operator()()

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

Format the specified record according to the current format and recordSeparator to the specified stream.

◆ operator=() [1/2]

RecordJsonFormatter & ball::RecordJsonFormatter::operator= ( bslmf::MovableRef< RecordJsonFormatter rhs)
inline

Assign to this object the format specification and record separator of the specified rhs object, and return a reference providing modifiable access to this object. The format specification and record separator of rhs are moved to this object, and all outstanding memory allocations and the allocator associated with rhs are adopted if get_allocator() == rhs.get_allocator(). rhs is left in a valid but unspecified state.

◆ operator=() [2/2]

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

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object.

◆ recordSeparator()

const bsl::string & ball::RecordJsonFormatter::recordSeparator ( ) const
inline

◆ setFormat()

int ball::RecordJsonFormatter::setFormat ( const bsl::string_view format)

Set the message format specification (see {Record Format Specification}) of this record JSON formatter to the specified format. Return 0 on success, and a non-zero value otherwise (if format is not valid JSON or not a JSON conforming to the expected schema).

◆ setRecordSeparator()

void ball::RecordJsonFormatter::setRecordSeparator ( const bsl::string_view recordSeparator)
inline

Set the record separator for this record JSON formatter to the specified recordSeparator. The recordSeparator will be printed by each invocation of operator() after the formatted record. The default is a single newline character, "\n".


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