Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

ball::RecordJsonFormatter Class Reference

#include <ball_recordjsonformatter.h>

List of all members.

Public Types

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

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (RecordJsonFormatter, bslma::UsesBslmaAllocator)
 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 ()
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
const allocator_typeallocator () const

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 Component ball_recordjsonformatter


Member Typedef Documentation

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

Constructor & Destructor Documentation

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".

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

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.

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

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.

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

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.allocator(). original is left in a valid but unspecified state.

ball::RecordJsonFormatter::~RecordJsonFormatter (  ) 

Destroy this object.


Member Function Documentation

ball::RecordJsonFormatter::BSLMF_NESTED_TRAIT_DECLARATION ( RecordJsonFormatter  ,
bslma::UsesBslmaAllocator   
)
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.

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

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 allocator() == rhs.allocator(). rhs is left in a valid but unspecified state.

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

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

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".

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.

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

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

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

Return the record separator of this record JSON formatter.

const allocator_type& ball::RecordJsonFormatter::allocator (  )  const

Return the allocator used by this object to supply memory.


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