BDE 4.39.x 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-basic-hierarchical-category-operations"> Example 1: Basic Hierarchical Category Operations </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.
44///
45/// **NOTE**: The functions in this component forward their calls through
46/// `ball::LoggerManager` to `ball::CategoryManager`, which contains the
47/// implementations of hierarchical category management. See
48/// @ref ball_categorymanager for comprehensive documentation on hierarchical
49/// category management, including detailed usage examples.
50///
51/// In particular, the `setThresholdLevelsHierarchically` function modifies the
52/// threshold levels of each category whose name has the specified string as a
53/// prefix, and the `addCategoryHierarchically` function creates a new category
54/// that inherits threshold levels from the existing category whose name is the
55/// longest prefix match, if such a category exists.
56///
57/// ## Deprecation Notice {#ball_loggercategoryutil-deprecation-notice}
58///
59///
60/// The `setThresholdLevels` function is deprecated in favor of
61/// `setThresholdLevelsHierarchically`. The former is data-sensitive in the
62/// sense that the `*` located at the end of the specified category name will
63/// be treated as a special flag to turn on the prefix name matching, thus
64/// causing trouble for categories whose name ends with `*`.
65///
66/// ## Usage {#ball_loggercategoryutil-usage}
67///
68///
69/// This section illustrates basic usage of this component's functions. For
70/// comprehensive usage examples demonstrating hierarchical category management,
71/// including inheritance of threshold levels and prefix-based threshold
72/// updates, see the "Usage" section in @ref ball_categorymanager .
73///
74/// ### Example 1: Basic Hierarchical Category Operations {#ball_loggercategoryutil-example-1-basic-hierarchical-category-operations}
75///
76///
77/// The following example demonstrates basic usage of
78/// `addCategoryHierarchically` and `setThresholdLevelsHierarchically`.
79///
80/// First, assume we have initialized the logger manager with default
81/// thresholds:
82/// @code
83/// ball::LoggerManager& lm = ball::LoggerManager::singleton();
84/// lm.setDefaultThresholdLevels(191, 95, 63, 31);
85/// @endcode
86/// Then, we create a base category:
87/// @code
88/// lm.addCategory("EQ", 192, 96, 64, 32);
89/// @endcode
90/// Next, we use `addCategoryHierarchically` to create a category that inherits
91/// from "EQ":
92/// @code
93/// ball::LoggerCategoryUtil::addCategoryHierarchically(&lm, "EQ.MARKET");
94/// @endcode
95/// The new category "EQ.MARKET" will inherit threshold levels [192, 96, 64, 32]
96/// from "EQ".
97///
98/// Finally, we update all categories under "EQ" using
99/// `setThresholdLevelsHierarchically`:
100/// @code
101/// ball::LoggerCategoryUtil::setThresholdLevelsHierarchically(&lm,
102/// "EQ",
103/// 194,
104/// 98,
105/// 66,
106/// 34);
107/// @endcode
108/// This will update threshold levels for both "EQ" and "EQ.MARKET".
109///
110/// For more detailed examples illustrating hierarchical category management,
111/// longest prefix matching, and threshold inheritance strategies, see the usage
112/// examples in @ref ball_categorymanager .
113/// @}
114/** @} */
115/** @} */
116
117/** @addtogroup bal
118 * @{
119 */
120/** @addtogroup ball
121 * @{
122 */
123/** @addtogroup ball_loggercategoryutil
124 * @{
125 */
126
127#include <balscm_version.h>
128
129#include <ball_loggermanager.h>
130
131#include <bsls_assert.h>
132
133
134namespace ball {
135
136class LoggerManager;
137class Category;
138
139 // =========================
140 // struct LoggerCategoryUtil
141 // =========================
142
143/// This struct provides a suite of utility functions that facilitate the
144/// management of the categories in `LoggerManager`.
145///
146/// See @ref ball_loggercategoryutil
148
149 // CLASS METHODS
150
151 /// Add, to the specified `loggerManager`, a new category having the
152 /// specified `categoryName`; return the address of the modifiable new
153 /// category on success, and 0, with no effect, if a category by that
154 /// name already exists or if the number of existing categories has reached
155 /// the maximum capacity. The newly created category will have its
156 /// threshold levels chosen primarily from two sources: threshold levels of
157 /// an existing category or a category setting (to which no category
158 /// exists) choosing the one whose name is the longest non-empty prefix of
159 /// `categoryName`. If such a category or setting exists, and the default
160 /// threshold levels (which might be overridden by a default threshold
161 /// levels callback) otherwise. See also
162 /// `ball::CategoryManager::addCategoryHierarchically`.
163 static Category *addCategoryHierarchically(LoggerManager *loggerManager,
164 const char *categoryName);
165
166 /// In case the specified `categoryNamePrefix` is not empty set, in the
167 /// specified `loggerManager`, the threshold levels of every existing and
168 /// future category whose name has, as a prefix, `categoryNamePrefix` to
169 /// the specified threshold values, `recordLevel`, `passLevel`,
170 /// `triggerLevel`, and `triggerAllLevel`. In case `categoryNamePrefix` is
171 /// empty set the threshold level of every existing category, and remove
172 /// all preliminary settings (for categories that do not exist yet).
173 /// Return the number of categories whose threshold levels were set, and a
174 /// negative value, with no effect, if any of the specified threshold
175 /// values is outside the range `[0 .. 255]`.
176 ///
177 /// \pre The behavior is undefined unless `loggerManager` is not in the process of being destroyed. See
178 /// also `ball::CategoryManager::setThresholdLevelsHierarchically`.
180 LoggerManager *loggerManager,
181 const char *categoryNamePrefix,
182 int recordLevel,
183 int passLevel,
184 int triggerLevel,
185 int triggerAllLevel);
186
187 /// Same as `setThresholdLevelsHierarchically` except that a `*` located at
188 /// the end of `pattern` is recognized as a special character and removed
189 /// before performing the operation. Thus, this function sets, in the
190 /// specified `loggerManager`, the threshold levels of every existing and
191 /// future category whose name has, as a prefix, the substring of
192 /// `pattern` excluding an optional trailing `*`, to the specified
193 /// threshold values, `recordLevel`, `passLevel`, `triggerLevel`, and
194 /// `triggerAllLevel`. In case `pattern` is `*` or empty, set the
195 /// threshold level of every existing category, and remove all preliminary
196 /// settings (for categories that do not exist yet). Return the number of
197 /// categories whose threshold levels were set, and a negative value, with
198 /// no effect, if any of the specified threshold values is outside the range `[0 .. 255]`.
199 ///
200 /// \pre The behavior is undefined unless `loggerManager`
201 /// is not in the process of being destroyed. See also
202 /// `setThresholdLevelsHierarchically` and
203 /// `ball::CategoryManager::setThresholdLevelsHierarchically`.
204 ///
205 /// @deprecated Use @ref setThresholdLevelsHierarchically instead.
206 static int setThresholdLevels(LoggerManager *loggerManager,
207 const char *pattern,
208 int recordLevel,
209 int passLevel,
210 int triggerLevel,
211 int triggerAllLevel);
212};
213
214
215// ============================================================================
216// INLINE DEFINITIONS
217// ============================================================================
218
219 // -------------------------
220 // struct LoggerCategoryUtil
221 // -------------------------
222// CLASS METHODS
223inline
225 LoggerManager *loggerManager,
226 const char *categoryName)
227{
228 BSLS_ASSERT(loggerManager);
229 BSLS_ASSERT(categoryName);
230 return loggerManager->addCategoryHierarchically(categoryName);
231}
232
233inline
235 LoggerManager *loggerManager,
236 const char *categoryNamePrefix,
237 int recordLevel,
238 int passLevel,
239 int triggerLevel,
240 int triggerAllLevel)
241{
242 BSLS_ASSERT(loggerManager);
243 BSLS_ASSERT(categoryNamePrefix);
244 return loggerManager->setThresholdLevelsHierarchically(categoryNamePrefix,
245 recordLevel,
246 passLevel,
247 triggerLevel,
248 triggerAllLevel);
249}
250
251
252} // close package namespace
253
254
255#endif
256
257// ----------------------------------------------------------------------------
258// Copyright 2015 Bloomberg Finance L.P.
259//
260// Licensed under the Apache License, Version 2.0 (the "License");
261// you may not use this file except in compliance with the License.
262// You may obtain a copy of the License at
263//
264// http://www.apache.org/licenses/LICENSE-2.0
265//
266// Unless required by applicable law or agreed to in writing, software
267// distributed under the License is distributed on an "AS IS" BASIS,
268// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
269// See the License for the specific language governing permissions and
270// limitations under the License.
271// ----------------------------- END-OF-FILE ----------------------------------
272
273/** @} */
274/** @} */
275/** @} */
Definition ball_category.h:184
Definition ball_loggermanager.h:1293
Category * addCategoryHierarchically(const char *categoryName)
Definition ball_loggermanager.h:2398
int setThresholdLevelsHierarchically(const char *categoryNamePrefix, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
Definition ball_loggermanager.h:2507
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#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_loggercategoryutil.h:147
static int setThresholdLevels(LoggerManager *loggerManager, const char *pattern, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static Category * addCategoryHierarchically(LoggerManager *loggerManager, const char *categoryName)
Definition ball_loggercategoryutil.h:224
static int setThresholdLevelsHierarchically(LoggerManager *loggerManager, const char *categoryNamePrefix, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
Definition ball_loggercategoryutil.h:234