[#BloombergLP-ball-AttributeContext]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/ball.adoc[ball]::AttributeContext
:relfileprefix: ../../
:mrdocs:

Mechanism for associating attributes with the current thread and evaluating logging rules&period;

== Synopsis

Declared in `&lt;ball&lowbar;attributecontext&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class AttributeContext;
----

== Description

This class provides a mechanism for associating attributes with the current thread, and evaluating the logging rules associated with a category using those stored attributes&period; `AttributeContext` contains class data members that must be initialized (using the `initialize` class method) with a `CategoryManager` object containing a `RuleSet` that represents the currently installed logging rules for the process&period; Clients can obtain the context for the current thread by calling the `getContext` class method&period; The `addAttributes` and `removeAttributes` methods are used to add and remove collections of attributes from the (thread&hyphen;local) context object&period; Finally, `AttributeContext` provides methods (used primarily by other components in the `ball` package&apos;) to determine the effect of the current logging rules on the logging thresholds of a category&period; The `hasRelevantActiveRules` method returns `true` if there are any relevant and active rules that might modify the logging thresholds of the supplied category&period; A rule is &quot;relevant&quot; if the rule&apos;s pattern matches the category&apos;s name, and a rule is &quot;active&quot; if all the attributes defined for the rule are satisfied by the current thread&apos;s attributes (i&period;e&period;, `Rule&colon;&colon;evaluate` returns `true` for the collection of attributes maintained for the current thread by the thread&apos;s `AttributeContext` object)&period; The `determineThresholdLevels` method returns the logging threshold levels for a category, factoring in any active rules that apply to the category that might override the category&apos;s thresholds&period; The behavior for the `hasRelevantActiveRules` and `determineThresholdLevels` methods is undefined unless `initialize` has been called&period; Note that, in practice, `initialize` is called _internally_ when the logger manager singleton is initialized&semi; clients ordinarily should not call `initialize` directly&period;

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/AttributeContext/iterator.adoc[`iterator`] 
| Iterator over the attribute containers in an `AttributeContext`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/AttributeContext/addAttributes.adoc[`addAttributes`] 
| Add the specified `attributes` container to this context&period;
| xref:BloombergLP/ball/AttributeContext/clearCache.adoc[`clearCache`] 
| Clear this object&apos;s cache of evaluated rules&period;
| xref:BloombergLP/ball/AttributeContext/containers.adoc[`containers`] 
| Return the list of attribute containers maintained by this object&period;
| xref:BloombergLP/ball/AttributeContext/determineThresholdLevels.adoc[`determineThresholdLevels`] 
| Populate the specified `levels` with the threshold levels for the specified `category`&period;
| xref:BloombergLP/ball/AttributeContext/hasAttribute.adoc[`hasAttribute`] 
| Return whether an attribute with the specified `value` exists in this context&period;
| xref:BloombergLP/ball/AttributeContext/hasRelevantActiveRules.adoc[`hasRelevantActiveRules`] 
| Return `true` if there is at least one relevant and active rule for the specified `category`&period;
| xref:BloombergLP/ball/AttributeContext/print.adoc[`print`] 
| Format this object to the specified output stream&period;
| xref:BloombergLP/ball/AttributeContext/removeAttributes.adoc[`removeAttributes`] 
| Remove the specified `element` from this context&apos;s attribute containers&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/AttributeContext/getContext.adoc[`getContext`] 
| Return the address of the current thread&apos;s attribute context, creating one if needed&period;
| xref:BloombergLP/ball/AttributeContext/initialize.adoc[`initialize`] 
| Initialize the static data members of `AttributeContext` using the specified `categoryManager`&period;
| xref:BloombergLP/ball/AttributeContext/lookupContext.adoc[`lookupContext`] 
| Return the address of the current thread&apos;s attribute context, or 0 if none exists&period;
| xref:BloombergLP/ball/AttributeContext/reset.adoc[`reset`] 
| Reset the static data members of `AttributeContext` to their initial state&period;
| xref:BloombergLP/ball/AttributeContext/visitAttributes.adoc[`visitAttributes`] 
| Invoke the specified `visitor` for all attributes in all attribute containers maintained by this object&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/ball/AttributeContextProctor.adoc[BloombergLP::ball::AttributeContextProctor]`
| Proctor that destroys the current thread&apos;s attribute context on destruction&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
