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

Detailed Description

Outline

Purpose

Provide a scoped guard for a single BALL attribute.

Classes

See also
ball_attribute

Description

This component defines a type, ball::ScopedAttribute, that serves as a scoped guard for ball::Attribute objects. It defines a single attribute for the current thread while it is in scope.

This component is used to associate an attribute (a name-value pair) with the current thread context for use when writing log records for the current thread. This context information can both be written to the log itself, and used as input when evaluating whether a particular log should be written. For more information on how to use this feature, please see the package level documentation and usage examples for "Log Attributes" and "Rule-Based Logging".

Usage

This section illustrates intended use of this component.

Example 1: Basic Usage of ball::ScopedAttribute

Suppose that service requests for a fictional service with id 999 are handled asynchronously by the function below. Creating an instance of this class will set BALL attributes for any logging performed while the request is being processed:

void handleServiceRequest(const Request& request)
{
BALL_LOG_SET_CATEGORY("MY.SERVICE");
ball::ScopedAttribute attribute("request", request.selectionName());
BALL_LOG_TRACE << "Handling request: " << request;
// handle request here
}
Definition ball_scopedattribute.h:230
#define BALL_LOG_SET_CATEGORY(CATEGORY)
Definition ball_log.h:1041
#define BALL_LOG_TRACE
Definition ball_log.h:1221

Attribute "request" will be set in the calling thread and will affect publication of any BALL messages for the lifetime of attribute.