BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball_recordformatterfunctor

Detailed Description

Provide a typedef for the record formatter functor.

Outline

Purpose

Provide a typedef for the record formatter functor.

Classes

See also
ball_record, ball_recordformatterregistryutil

Description

This component provides a struct, ball::RecordFormatterFunctor, that contains a single typedef, Type, which is the type of the functor used for formatting log records to a stream.

Usage

This section illustrates intended use of this component.

Example 1: Defining a Record Formatter Function

Suppose we want to define a simple function that formats log records. We can use ball::RecordFormatterFunctor::Type to declare a functor that conforms to the expected signature.

First, we include the necessary headers and define a simple formatting function:

void myFormatter(bsl::ostream& stream, const ball::Record& record)
{
stream << "Log: " << record.fixedFields().message();
}
const char * message() const
Definition ball_record.h:176
RecordAttributes & fixedFields()
Return the modifiable fixed fields of this log record.
Definition ball_record.h:397

Then, we can assign this function to a variable of the functor type:

ball::RecordFormatterFunctor::Type formatter = &myFormatter;
Forward declaration.
Definition bslstl_function.h:946

Finally, we can use this functor to format a record:

attr.setMessage("Hello");
ball::Record record(attr, ball::UserFields());
formatter(oss, record);
assert(oss.str() == "Log: Hello");
Definition ball_recordattributes.h:275
void setMessage(const bsl::string_view &message)
Definition ball_userfields.h:136
basic_ostringstream< char, char_traits< char >, allocator< char > > ostringstream
Definition bslstl_iosfwd.h:97