|
BDE 4.39.x Production Release
|
#include <ball_recordjsonformatter.h>
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.
Public Types | |
| enum | SpecSyntax { e_JSON , e_SIMPLIFIED } |
| typedef bsl::vector< RecordJsonFormatter_FieldFormatter * > | FieldFormatters |
| typedef bsl::allocator | allocator_type |
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) |
| 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.
|
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:
The default record separator is "\n".
|
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.
|
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.
|
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.
| ball::RecordJsonFormatter::~RecordJsonFormatter | ( | ) |
Destroy this object.
|
inline |
|
inline |
Return the message format specification of this record JSON formatter. See {Record Format Specification}.
formatSyntax().
|
inline |
Return the message format specification syntax of this record JSON formatter. See {Record Format Specification}.
|
inline |
Return the allocator used by this object to supply memory.
|
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.
|
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.
| 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.
|
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.
| 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.
|
inline |
Return the record separator of this record JSON formatter.
| 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 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).
| 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).
json:// scheme.
|
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".
| 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.
| 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.
|
inline |
Get the time zone default setting.