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

#include <ball_recordjsonformatter.h>

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 a message format specification supplied either by setJsonFormat or setSimplifiedFormat manipulator or the default format installed by the constructor) and outputs the result to the stream. While 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) it is advised to use the more flexible scheme-based format selection provided now by every BDE-made observer.

See ball_recordjsonformatter

Public Types

enum  SpecSyntax { e_JSON , e_SIMPLIFIED }
 
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 ()
 
RecordJsonFormatteroperator= (const RecordJsonFormatter &rhs)
 
RecordJsonFormatteroperator= (bslmf::MovableRef< RecordJsonFormatter > rhs)
 
int setJsonFormat (const bsl::string_view &format)
 
int setFormat (const bsl::string_view &format)
 
int setSimplifiedFormat (const bsl::string_view &format)
 
void setTimezoneDefault (RecordFormatterTimezone::Enum timezoneDefault)
 
void setRecordSeparator (const bsl::string_view &recordSeparator)
 
void operator() (bsl::ostream &stream, const Record &record) const
 
const bsl::stringformat () const
 
SpecSyntax formatSyntax () const
 
RecordFormatterTimezone::Enum timezoneDefault () const
 
const bsl::stringrecordSeparator () const
 
BSLS_DEPRECATE bslma::Allocatorallocator () const
 
allocator_type get_allocator () const
 

Static Public Member Functions

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

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.

Member Enumeration Documentation

◆ SpecSyntax

Enumerator to determine the syntax of the specification string.

Enumerator
e_JSON 
e_SIMPLIFIED 

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

Destroy this object.

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

Note
Note that the syntax of this string depends on formatSyntax().

◆ formatSyntax()

RecordJsonFormatter::SpecSyntax ball::RecordJsonFormatter::formatSyntax ( ) const
inline

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

◆ get_allocator()

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

Return the allocator used by this object to supply memory.

◆ loadJsonSchemeFormatter()

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

This class method configures a formatter for the "json" 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 not modified.

◆ loadQjsonSchemeFormatter()

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

This class method configures a formatter for the "qjson" 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 not modified.

◆ 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

Return the record separator of this record JSON formatter.

◆ setFormat()

int ball::RecordJsonFormatter::setFormat ( const bsl::string_view format)
Deprecated:
Use setJsonFormat instead.

Set the message format specification (see {Record Format Specification}) of this record JSON formatter to the specified JSON-syntax 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).

◆ setJsonFormat()

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

Set the message format specification (see {Record Format Specification}) of this record JSON formatter to the specified JSON-syntax 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).

Note
Note that this is the method used by the json:// scheme.

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

◆ setSimplifiedFormat()

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

Parse the simplified format specification (see {Simplified Record Format Specification}) in the specified format and configure this formatter accordingly. Return 0 on success, and a non-zero value otherwise.

◆ setTimezoneDefault()

void ball::RecordJsonFormatter::setTimezoneDefault ( RecordFormatterTimezone::Enum  timezoneDefault)

Set the time zone default for every "timestamp" output without a timezone specified in the format string to the specified timezoneDefault.

Note
Note that this method reapplies the current format specification to update all timestamp formatters.

◆ timezoneDefault()

RecordFormatterTimezone::Enum ball::RecordJsonFormatter::timezoneDefault ( ) const
inline

Get the time zone default setting.


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