BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball_loggercategoryutil.h
Go to the documentation of this file.
1/// @file ball_loggercategoryutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_loggercategoryutil.h -*-C++-*-
8#ifndef INCLUDED_BALL_LOGGERCATEGORYUTIL
9#define INCLUDED_BALL_LOGGERCATEGORYUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_loggercategoryutil ball_loggercategoryutil
15/// @brief Provide a suite of utility functions for category management.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_loggercategoryutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_loggercategoryutil-purpose"> Purpose</a>
25/// * <a href="#ball_loggercategoryutil-classes"> Classes </a>
26/// * <a href="#ball_loggercategoryutil-description"> Description </a>
27/// * <a href="#ball_loggercategoryutil-deprecation-notice"> Deprecation Notice </a>
28/// * <a href="#ball_loggercategoryutil-usage"> Usage </a>
29/// * <a href="#ball_loggercategoryutil-example-1-managing-categories"> Example 1: Managing Categories </a>
30///
31/// # Purpose {#ball_loggercategoryutil-purpose}
32/// Provide a suite of utility functions for category management.
33///
34/// # Classes {#ball_loggercategoryutil-classes}
35///
36/// - ball::LoggerCategoryUtil: namespace for category management utilities
37///
38/// @see ball_loggermanager, ball_categorymanager
39///
40/// # Description {#ball_loggercategoryutil-description}
41/// This component defines a `struct`, `ball::LoggerCategoryUtil`,
42/// that provides a set of utility functions for managing the categories
43/// contained in a `ball::LoggerManager` based on the notion of hierarchy. In
44/// particular, the `setThresholdLevelsHierarchically` function modifies the
45/// threshold levels of each category in `ball::LoggerManager` whose name has
46/// the specified string as a prefix. The `addCategoryHierarchically` function
47/// creates a new category that inherits threshold levels from the exiting
48/// category whose name is the longest prefix match, if such a category exists.
49///
50/// ## Deprecation Notice {#ball_loggercategoryutil-deprecation-notice}
51///
52///
53/// The `setThresholdLevels` function is deprecated in favor of
54/// `setThresholdLevelsHierarchically`. The former is data-sensitive in the
55/// sense that the `*` located at the end of the specified category name will
56/// be treated as a special flag to turn on the prefix name matching, thus
57/// causing trouble for categories whose name ends with `*`.
58///
59/// ## Usage {#ball_loggercategoryutil-usage}
60///
61///
62/// This section illustrates intended use of this component.
63///
64/// ### Example 1: Managing Categories {#ball_loggercategoryutil-example-1-managing-categories}
65///
66///
67/// The following code fragments illustrate basic usage of this component's
68/// `setThresholdLevelsHierarchically` and `addCategoryHierarchically` methods.
69///
70/// First, we create two auxiliary functions that serve to print out the names
71/// and threshold level values of all the categories currently in the logger
72/// manager singleton:
73/// @code
74/// void printCategory(const ball::Category *category)
75/// {
76/// bsl::cout << "\t[ " << category->categoryName()
77/// << ", " << category->recordLevel()
78/// << ", " << category->passLevel()
79/// << ", " << category->triggerLevel()
80/// << ", " << category->triggerAllLevel()
81/// << " ]" << bsl::endl;
82/// }
83///
84/// void printAllCategories()
85/// {
86/// ball::LoggerManager& lm = ball::LoggerManager::singleton();
87/// using namespace bdlf::PlaceHolders;
88/// lm.visitCategories(bdlf::BindUtil::bind(printCategory, _1));
89/// }
90/// @endcode
91/// Now, we set the default threshold levels of the logger manager object to
92/// [191, 95, 63, 31] (for brevity, the initialization of the logger manager
93/// singleton is elided):
94/// @code
95/// ball::LoggerManager& lm = ball::LoggerManager::singleton();
96/// lm.setDefaultThresholdLevels(191, 95, 63, 31);
97/// @endcode
98/// Then, we create two new categories, "EQ" and "EQ.MARKET", by calling the
99/// `addCategory` method of the logger manager class, with their threshold
100/// levels explicitly set to different values (which are also different from the
101/// default threshold levels):
102/// @code
103/// lm.addCategory("EQ", 192, 96, 64, 32);
104/// lm.addCategory("EQ.MARKET", 193, 97, 65, 33);
105/// printAllCategories();
106/// @endcode
107/// The following is printed out by `printAllCategories`:
108/// @code
109/// [ EQ, 192, 96, 64, 32 ]
110/// [ EQ.MARKET, 193, 97, 65, 33 ]
111/// @endcode
112/// Next, we add a new category using `addCategoryHierarchically`:
113/// @code
114/// ball::LoggerCategoryUtil::addCategoryHierarchically(&lm,
115/// "EQ.MARKET.NYSE");
116/// printAllCategories();
117/// @endcode
118/// The new category with name "EQ.MARKET.NYSE" inherits its threshold levels
119/// from the category "EQ.MARKET" rather than having the default threshold
120/// levels or inheriting them from "EQ" because of the longest prefix matching
121/// rule:
122/// @code
123/// [ EQ, 192, 96, 64, 32 ]
124/// [ EQ.MARKET, 193, 97, 65, 33 ]
125/// [ EQ.MARKET.NYSE, 193, 97, 65, 33 ]
126/// @endcode
127/// Then, we adjust the threshold levels for all categories whose name starts
128/// with "EQ.MARKET" using `setThresholdLevelsHierarchically`:
129/// @code
130/// ball::LoggerCategoryUtil::setThresholdLevelsHierarchically(&lm,
131/// "EQ.MARKET",
132/// 194,
133/// 98,
134/// 66,
135/// 34);
136/// printAllCategories();
137/// @endcode
138/// We will notice that the threshold levels of "EQ.MARKET" and
139/// "EQ.MARKET.NYSE" have been changed to the new values, while those of "EQ"
140/// remain unchanged:
141/// @code
142/// [ EQ, 192, 96, 64, 32 ]
143/// [ EQ.MARKET, 194, 98, 66, 34 ]
144/// [ EQ.MARKET.NYSE, 194, 98, 66, 34 ]
145/// @endcode
146/// @}
147/** @} */
148/** @} */
149
150/** @addtogroup bal
151 * @{
152 */
153/** @addtogroup ball
154 * @{
155 */
156/** @addtogroup ball_loggercategoryutil
157 * @{
158 */
159
160#include <balscm_version.h>
161
162
163namespace ball {
164
165class LoggerManager;
166class Category;
167
168 // =========================
169 // struct LoggerCategoryUtil
170 // =========================
171
172/// This struct provides a suite of utility functions that facilitate the
173/// management of the categories in `LoggerManager`.
175
176 // CLASS METHODS
177
178 /// Add, to the specified `loggerManager`, a new category having the
179 /// specified `categoryName`; return the address of the modifiable new
180 /// category on success, and 0, with no effect, if a category by that
181 /// name already exists or if the number of existing categories in
182 /// `loggerManager` has reached the maximum capacity. The newly created
183 /// category will have the same threshold levels as the category in
184 /// `loggerManager` whose name is the longest non-empty prefix of
185 /// `categoryName` if such a category exists, and the default threshold
186 /// levels of `loggermanager` (which might be overridden by a default
187 /// threshold levels callback) otherwise.
189 const char *categoryName);
190
191 /// Set, in the specified `loggerManager`, the threshold levels of every
192 /// category whose name has, as a prefix, the specified
193 /// `categoryNamePrefix` to the specified threshold values,
194 /// `recordLevel`, `passLevel`, `triggerLevel`, and `triggerAllLevel`.
195 /// Return the number of categories whose threshold levels were set, and
196 /// a negative value, with no effect, if any of the specified threshold
197 /// values is outside the range `[0 .. 255]`. The behavior is undefined
198 /// unless `loggerManager` is not null and `categoryNamePrefix` is
199 /// null-terminated.
201 LoggerManager *loggerManager,
202 const char *categoryNamePrefix,
203 int recordLevel,
204 int passLevel,
205 int triggerLevel,
206 int triggerAllLevel);
207
208 /// Set the threshold levels of each category currently in the registry
209 /// of the specified `loggerManager` whose name matches the specified
210 /// `pattern` to the specified `recordLevel`, `passLevel`,
211 /// `triggerLevel`, and `triggerAllLevel` values, respectively, if each
212 /// of the threshold values is in the range `[0 .. 255]`. Return the
213 /// number of categories whose threshold levels were set, and a negative
214 /// value if any of the threshold values were invalid. `pattern` is
215 /// assumed to be of the form "X" or "X*" where X is a sequence of 0 or
216 /// more characters and `*` matches any string (including the empty
217 /// string). The behavior is undefined unless `loggerManager` is not in
218 /// the process of being destroyed. Note that only a `*` located at the
219 /// end of `pattern` is recognized as a special character. Also note
220 /// that this function has no effect on the threshold levels of
221 /// categories added to the registry after it is called.
222 ///
223 /// @deprecated Use @ref setThresholdLevelsHierarchically instead.
224 static int setThresholdLevels(LoggerManager *loggerManager,
225 const char *pattern,
226 int recordLevel,
227 int passLevel,
228 int triggerLevel,
229 int triggerAllLevel);
230};
231
232} // close package namespace
233
234
235#endif
236
237// ----------------------------------------------------------------------------
238// Copyright 2015 Bloomberg Finance L.P.
239//
240// Licensed under the Apache License, Version 2.0 (the "License");
241// you may not use this file except in compliance with the License.
242// You may obtain a copy of the License at
243//
244// http://www.apache.org/licenses/LICENSE-2.0
245//
246// Unless required by applicable law or agreed to in writing, software
247// distributed under the License is distributed on an "AS IS" BASIS,
248// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
249// See the License for the specific language governing permissions and
250// limitations under the License.
251// ----------------------------- END-OF-FILE ----------------------------------
252
253/** @} */
254/** @} */
255/** @} */
Definition ball_category.h:184
Definition ball_loggermanager.h:1257
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition ball_administration.h:214
Definition ball_loggercategoryutil.h:174
static int setThresholdLevels(LoggerManager *loggerManager, const char *pattern, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static int setThresholdLevelsHierarchically(LoggerManager *loggerManager, const char *categoryNamePrefix, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static Category * addCategoryHierarchically(LoggerManager *loggerManager, const char *categoryName)