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

Detailed Description

Outline

Purpose

Provide a suite of utility functions for category management.

Classes

See also
ball_loggermanager, ball_categorymanager

Description

This component defines a struct, ball::LoggerCategoryUtil, that provides a set of utility functions for managing the categories contained in a ball::LoggerManager based on the notion of hierarchy. In particular, the setThresholdLevelsHierarchically function modifies the threshold levels of each category in ball::LoggerManager whose name has the specified string as a prefix. The addCategoryHierarchically function creates a new category that inherits threshold levels from the exiting category whose name is the longest prefix match, if such a category exists.

Deprecation Notice

The setThresholdLevels function is deprecated in favor of setThresholdLevelsHierarchically. The former is data-sensitive in the sense that the * located at the end of the specified category name will be treated as a special flag to turn on the prefix name matching, thus causing trouble for categories whose name ends with *.

Usage

This section illustrates intended use of this component.

Example 1: Managing Categories

The following code fragments illustrate basic usage of this component's setThresholdLevelsHierarchically and addCategoryHierarchically methods.

First, we create two auxiliary functions that serve to print out the names and threshold level values of all the categories currently in the logger manager singleton:

void printCategory(const ball::Category *category)
{
bsl::cout << "\t[ " << category->categoryName()
<< ", " << category->recordLevel()
<< ", " << category->passLevel()
<< ", " << category->triggerLevel()
<< ", " << category->triggerAllLevel()
<< " ]" << bsl::endl;
}
void printAllCategories()
{
using namespace bdlf::PlaceHolders;
lm.visitCategories(bdlf::BindUtil::bind(printCategory, _1));
}
Definition ball_category.h:184
int triggerLevel() const
Return the trigger level of this category.
Definition ball_category.h:545
int triggerAllLevel() const
Return the trigger-all level of this category.
Definition ball_category.h:552
const char * categoryName() const
Return the name of this category.
Definition ball_category.h:513
int recordLevel() const
Return the record level of this category.
Definition ball_category.h:531
int passLevel() const
Return the pass level of this category.
Definition ball_category.h:538
Definition ball_loggermanager.h:1257
void visitCategories(const t_CATEGORY_VISITOR &visitor)
Definition ball_loggermanager.h:2412
static LoggerManager & singleton()
Definition ball_loggermanager.h:2290
static Bind< bslmf::Nil, t_FUNC, Bind_BoundTuple0 > bind(t_FUNC func)
Definition bdlf_bind.h:1830
Definition bdlf_placeholder.h:82

Now, we set the default threshold levels of the logger manager object to [191, 95, 63, 31] (for brevity, the initialization of the logger manager singleton is elided):

lm.setDefaultThresholdLevels(191, 95, 63, 31);
int setDefaultThresholdLevels(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)

Then, we create two new categories, "EQ" and "EQ.MARKET", by calling the addCategory method of the logger manager class, with their threshold levels explicitly set to different values (which are also different from the default threshold levels):

lm.addCategory("EQ", 192, 96, 64, 32);
lm.addCategory("EQ.MARKET", 193, 97, 65, 33);
printAllCategories();
Category * addCategory(const char *categoryName, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)

The following is printed out by printAllCategories:

[ EQ, 192, 96, 64, 32 ]
[ EQ.MARKET, 193, 97, 65, 33 ]

Next, we add a new category using addCategoryHierarchically:

"EQ.MARKET.NYSE");
printAllCategories();
static Category * addCategoryHierarchically(LoggerManager *loggerManager, const char *categoryName)

The new category with name "EQ.MARKET.NYSE" inherits its threshold levels from the category "EQ.MARKET" rather than having the default threshold levels or inheriting them from "EQ" because of the longest prefix matching rule:

[ EQ, 192, 96, 64, 32 ]
[ EQ.MARKET, 193, 97, 65, 33 ]
[ EQ.MARKET.NYSE, 193, 97, 65, 33 ]

Then, we adjust the threshold levels for all categories whose name starts with "EQ.MARKET" using setThresholdLevelsHierarchically:

"EQ.MARKET",
194,
98,
66,
34);
printAllCategories();
static int setThresholdLevelsHierarchically(LoggerManager *loggerManager, const char *categoryNamePrefix, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)

We will notice that the threshold levels of "EQ.MARKET" and "EQ.MARKET.NYSE" have been changed to the new values, while those of "EQ" remain unchanged:

[ EQ, 192, 96, 64, 32 ]
[ EQ.MARKET, 194, 98, 66, 34 ]
[ EQ.MARKET.NYSE, 194, 98, 66, 34 ]