BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball_record

Detailed Description

Outline

Purpose

Provide a container for the fields and attributes of a log record.

Classes

See also
ball_recordattributes, ball_logger

Description

This component provides a single, unconstrained (value-semantic) attribute class, ball::Record, that is used to describe the properties of a logged message.

Attributes

Name Type
------------------ -----------------------------------
userFields ball::UserFields
Definition ball_recordattributes.h:274
Definition ball_userfields.h:136
Definition bslstl_vector.h:1025

ball::Record aggregates a set of fixed fields and various user-defined fields and attributes into one record type, useful for transmitting a customized log record as a single instance rather than passing around individual attributes separately. Note that this class is a pure attribute class with no constraints, other than the total memory required for the class. Also note that this class is not thread-safe.

Usage

This section illustrates intended use of this component.

Example 1: Basic Use of ball::Record

The following example demonstrates how to create and set the properties of a ball::Record. Note that users of the ball logging subsystem are not expected to create records directly.

First we default create a ball::Record, record, and verify it has a default set of attributes:

ball::Record record;
assert(ball::RecordAttributes() == record.fixedFields());
assert(0 == record.customFields().length());
Definition ball_record.h:178
ball::UserFields & customFields()
Definition ball_record.h:414
RecordAttributes & fixedFields()
Return the modifiable fixed fields of this log record.
Definition ball_record.h:396
int length() const
Return the number of user field values in this object.
Definition ball_userfields.h:406

Then, we set the fixed fields of the record to contain a simple message:

processId, // process id
threadId, // thread id
__FILE__, // filename
__LINE__, // line number
"ExampleCategory", // category
"Simple Test Message"); // message
record.setFixedFields(attributes);
assert(attributes == record.fixedFields());
void setFixedFields(const RecordAttributes &fixedFields)
Definition ball_record.h:402
@ e_WARN
Definition ball_severity.h:171
static int getProcessId()
static Datetime utc()
Definition bdlt_currenttime.h:296
static bsls::Types::Uint64 selfIdAsUint64()
Definition bslmt_threadutil.h:1100
unsigned long long Uint64
Definition bsls_types.h:137

Next, we add an additional attribute to the log record:

record.addAttribute(ball::Attribute("myLib.name", "John Smith"));
Definition ball_attribute.h:198
void addAttribute(const ball::Attribute &attribute)
Definition ball_record.h:382

Finally, we write the record to a stream:

output << record << bsl::endl;
Definition bslstl_ostringstream.h:175