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

Detailed Description

Provide category related callback function types.

Outline

Purpose

Provide category related callback function types.

Classes

See also
ball_loggermanagerdefaults, ball_categorymanager

Description

This component provides a namespace for category related callback function types. CategoryCallbacks::NameFilter is used to translate external category names to internal names, while CategoryCallbacks::DefaultThresholdLevels is used to determine default threshold levels for new categories.

Usage

This section illustrates intended use of this component.

Example 1: Using NameFilter

In this example, we demonstrate how to use the NameFilter callback type to translate category names. Suppose we want to add a prefix to all category names:

First, we define a function that implements the name filtering logic:

void myNameFilter(bsl::string *result, const char *categoryName)
{
*result = bsl::string("filtered_") + categoryName;
}
Definition bslstl_string.h:1252
basic_string< char > string
Definition bslstl_string.h:844

Then, we create a NameFilter object and assign our function to it:

ball::CategoryCallbacks::NameFilter filter = myNameFilter;
bsl::function< void(bsl::string *buffer, const char *categoryName)> NameFilter
Definition ball_categorycallbacks.h:173

Now, we can use the filter to transform category names:

bsl::string result;
filter(&result, "myCategory");
assert(result == "filtered_myCategory");

Example 2: Using DefaultThresholdLevels

In this example, we demonstrate how to use the DefaultThresholdLevels callback type to set default threshold levels for categories.

First, we define a function that implements the threshold level logic. In this example, we provide more verbose logging for categories starting with "CORE":

void myThresholdLevels(int *recordLevel,
int *passLevel,
int *triggerLevel,
int *triggerAllLevel,
const char *categoryName)
{
if (0 == bsl::strncmp(categoryName, "CORE", 4)) {
// More verbose logging for CORE categories
*recordLevel = 192;
*passLevel = 128;
*triggerLevel = 96;
*triggerAllLevel = 64;
}
else {
// Standard logging for other categories
*recordLevel = 160;
*passLevel = 96;
*triggerLevel = 64;
*triggerAllLevel = 32;
}
}

Then, we create a DefaultThresholdLevels object and assign our function to it:

myThresholdLevels;
Forward declaration.
Definition bslstl_function.h:946

Finally, we can use the callback to obtain threshold levels:

int recordLevel, passLevel, triggerLevel, triggerAllLevel;
thresholds(&recordLevel,
&passLevel,
&triggerLevel,
&triggerAllLevel,
"TEST.CATEGORY");
assert(160 == recordLevel);
assert(96 == passLevel);
assert(64 == triggerLevel);
assert(32 == triggerAllLevel);