Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component ball_scopedattribute
[Package ball]

Provide a scoped guard for a single BALL attribute. More...

Namespaces

namespace  ball

Detailed Description

Outline
Purpose:
Provide a scoped guard for a single BALL attribute.
Classes:
ball::ScopedAttribute single attribute scoped guard
See also:
Component 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
  }
Attribute "request" will be set in the calling thread and will affect publication of any BALL messages for the lifetime of attribute.