BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball_categorycallbacks.h
Go to the documentation of this file.
1/// @file ball_categorycallbacks.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_categorycallbacks.h -*-C++-*-
8#ifndef INCLUDED_BALL_CATEGORYCALLBACKS
9#define INCLUDED_BALL_CATEGORYCALLBACKS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_categorycallbacks ball_categorycallbacks
15/// @brief Provide category related callback function types.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_categorycallbacks
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_categorycallbacks-purpose"> Purpose</a>
25/// * <a href="#ball_categorycallbacks-classes"> Classes </a>
26/// * <a href="#ball_categorycallbacks-description"> Description </a>
27/// * <a href="#ball_categorycallbacks-usage"> Usage </a>
28/// * <a href="#ball_categorycallbacks-example-1-using-namefilter"> Example 1: Using NameFilter </a>
29/// * <a href="#ball_categorycallbacks-example-2-using-defaultthresholdlevels"> Example 2: Using DefaultThresholdLevels </a>
30///
31/// # Purpose {#ball_categorycallbacks-purpose}
32/// Provide category related callback function types.
33///
34/// # Classes {#ball_categorycallbacks-classes}
35///
36/// - ball::CategoryCallbacks: category related callback function types
37///
38/// @see ball_loggermanagerdefaults, ball_categorymanager
39///
40/// # Description {#ball_categorycallbacks-description}
41/// This component provides a namespace for category related
42/// callback function types. `CategoryCallbacks::NameFilter` is used to
43/// translate external category names to internal names, while
44/// `CategoryCallbacks::DefaultThresholdLevels` is used to determine default
45/// threshold levels for new categories.
46///
47/// ## Usage {#ball_categorycallbacks-usage}
48///
49///
50/// This section illustrates intended use of this component.
51///
52/// ### Example 1: Using NameFilter {#ball_categorycallbacks-example-1-using-namefilter}
53///
54///
55/// In this example, we demonstrate how to use the `NameFilter` callback type
56/// to translate category names. Suppose we want to add a prefix to all
57/// category names:
58///
59/// First, we define a function that implements the name filtering logic:
60/// @code
61/// void myNameFilter(bsl::string *result, const char *categoryName)
62/// {
63/// *result = bsl::string("filtered_") + categoryName;
64/// }
65/// @endcode
66/// Then, we create a `NameFilter` object and assign our function to it:
67/// @code
68/// ball::CategoryCallbacks::NameFilter filter = myNameFilter;
69/// @endcode
70/// Now, we can use the filter to transform category names:
71/// @code
72/// bsl::string result;
73/// filter(&result, "myCategory");
74/// assert(result == "filtered_myCategory");
75/// @endcode
76///
77/// ### Example 2: Using DefaultThresholdLevels {#ball_categorycallbacks-example-2-using-defaultthresholdlevels}
78///
79///
80/// In this example, we demonstrate how to use the `DefaultThresholdLevels`
81/// callback type to set default threshold levels for categories.
82///
83/// First, we define a function that implements the threshold level logic. In
84/// this example, we provide more verbose logging for categories starting with
85/// "CORE":
86/// @code
87/// void myThresholdLevels(int *recordLevel,
88/// int *passLevel,
89/// int *triggerLevel,
90/// int *triggerAllLevel,
91/// const char *categoryName)
92/// {
93/// if (0 == bsl::strncmp(categoryName, "CORE", 4)) {
94/// // More verbose logging for CORE categories
95/// *recordLevel = 192;
96/// *passLevel = 128;
97/// *triggerLevel = 96;
98/// *triggerAllLevel = 64;
99/// }
100/// else {
101/// // Standard logging for other categories
102/// *recordLevel = 160;
103/// *passLevel = 96;
104/// *triggerLevel = 64;
105/// *triggerAllLevel = 32;
106/// }
107/// }
108/// @endcode
109/// Then, we create a `DefaultThresholdLevels` object and assign our function
110/// to it:
111/// @code
112/// ball::CategoryCallbacks::DefaultThresholdLevels thresholds =
113/// myThresholdLevels;
114/// @endcode
115/// Finally, we can use the callback to obtain threshold levels:
116/// @code
117/// int recordLevel, passLevel, triggerLevel, triggerAllLevel;
118/// thresholds(&recordLevel,
119/// &passLevel,
120/// &triggerLevel,
121/// &triggerAllLevel,
122/// "TEST.CATEGORY");
123///
124/// assert(160 == recordLevel);
125/// assert(96 == passLevel);
126/// assert(64 == triggerLevel);
127/// assert(32 == triggerAllLevel);
128/// @endcode
129/// @}
130/** @} */
131/** @} */
132
133/** @addtogroup bal
134 * @{
135 */
136/** @addtogroup ball
137 * @{
138 */
139/** @addtogroup ball_categorycallbacks
140 * @{
141 */
142
143#include <balscm_version.h>
144
145#include <bsl_functional.h>
146#include <bsl_string.h>
147
148
149namespace ball {
150
151 // =======================
152 // class CategoryCallbacks
153 // =======================
154
155/// This struct provides a namespace for default threshold level related
156/// callback function types.
157///
158/// See @ref ball_categorycallbacks
160
161 // TYPES
162
163 /// An alias to a function meeting the following contract:
164 /// @code
165 /// /// Load into the specified `buffer` the internal name to be used as
166 /// /// the key in the `CategoryManager` registry for the specified
167 /// /// external `categoryName`, or leave `buffer` unmodified to use
168 /// /// `categoryName` as-is.
169 /// void nameFilter(bsl::string *buffer, const char *categoryName);
170 /// @endcode
171 /// See also `CategoryManager`.
172 typedef bsl::function<void(bsl::string *buffer, const char *categoryName)>
174
175 /// An alias to a function meeting the following contract:
176 /// @code
177 /// /// Load into the specified `recordLevel`, `passLevel`, `triggerLevel`,
178 /// /// and `triggerAllLevel` the default hierarchical threshold level
179 /// /// settings for the specified `categoryName`.
180 /// void defaultThresholdLevels(int *recordLevel,
181 /// int *passLevel,
182 /// int *triggerLevel,
183 /// int *triggerAllLevel,
184 /// const char *categoryName);
185 /// @endcode
186 typedef bsl::function<void(int *recordLevel,
187 int *passLevel,
188 int *triggerLevel,
189 int *triggerAllLevel,
190 const char *categoryName)>
192};
193
194} // close package namespace
195
196
197#endif // INCLUDED_BALL_CATEGORYCALLBACKS
198
199// ----------------------------------------------------------------------------
200// Copyright 2025 Bloomberg Finance L.P.
201//
202// Licensed under the Apache License, Version 2.0 (the "License");
203// you may not use this file except in compliance with the License.
204// You may obtain a copy of the License at
205//
206// http://www.apache.org/licenses/LICENSE-2.0
207//
208// Unless required by applicable law or agreed to in writing, software
209// distributed under the License is distributed on an "AS IS" BASIS,
210// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
211// See the License for the specific language governing permissions and
212// limitations under the License.
213// ----------------------------- END-OF-FILE ----------------------------------
214
215/** @} */
216/** @} */
217/** @} */
Definition bslstl_string.h:1252
Forward declaration.
Definition bslstl_function.h:946
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition ball_administration.h:214
Definition ball_categorycallbacks.h:159
bsl::function< void(int *recordLevel, int *passLevel, int *triggerLevel, int *triggerAllLevel, const char *categoryName)> DefaultThresholdLevels
Definition ball_categorycallbacks.h:191
bsl::function< void(bsl::string *buffer, const char *categoryName)> NameFilter
Definition ball_categorycallbacks.h:173