BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball_administration.h
Go to the documentation of this file.
1/// @file ball_administration.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_administration.h -*-C++-*-
8#ifndef INCLUDED_BALL_ADMINISTRATION
9#define INCLUDED_BALL_ADMINISTRATION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_administration ball_administration
15/// @brief Provide a suite of utility functions for logging administration.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_administration
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_administration-purpose"> Purpose</a>
25/// * <a href="#ball_administration-classes"> Classes </a>
26/// * <a href="#ball_administration-description"> Description </a>
27/// * <a href="#ball_administration-usage"> Usage </a>
28/// * <a href="#ball_administration-example-1-managing-categories"> Example 1: Managing Categories </a>
29///
30/// # Purpose {#ball_administration-purpose}
31/// Provide a suite of utility functions for logging administration.
32///
33/// # Classes {#ball_administration-classes}
34///
35/// - ball::Administration: namespace for logging administration utilities
36///
37/// @see ball_loggermanager
38///
39/// # Description {#ball_administration-description}
40/// This component provides a namespace, `ball::Administration`,
41/// containing a suite of utility functions to facilitate administration of the
42/// `ball` logging subsystem from a console operator's perspective. Utilities
43/// are provided for adding a category to the registry maintained by the
44/// singleton instance of `ball::LoggerManager` (hereafter the "logger
45/// manager"), for setting the threshold levels of one or more categories, for
46/// setting a limit on the maximum number of categories allowed, and for
47/// retrieving the threshold levels of (established) categories. Note that a
48/// precondition of all of the utility functions is that the logger manager
49/// singleton must be initialized and not in the process of being shut down.
50///
51/// ## Usage {#ball_administration-usage}
52///
53///
54/// This section illustrates intended use of this component.
55///
56/// ### Example 1: Managing Categories {#ball_administration-example-1-managing-categories}
57///
58///
59/// The code fragments in this example demonstrate several administration
60/// utilities that are used to create categories, and to set and access their
61/// threshold levels.
62///
63/// First we initialize the logger manager (for the purposes of this example,
64/// we use a minimal configuration):
65/// @code
66/// ball::LoggerManagerConfiguration lmConfig;
67/// ball::LoggerManagerScopedGuard lmGuard(lmConfig);
68/// @endcode
69/// Next define some hypothetical category names:
70/// @code
71/// const char *equityCategories[] = {
72/// "EQUITY.MARKET.NYSE",
73/// "EQUITY.MARKET.NASDAQ",
74/// "EQUITY.GRAPHICS.MATH.FACTORIAL",
75/// "EQUITY.GRAPHICS.MATH.ACKERMANN"
76/// };
77/// const int NUM_CATEGORIES = sizeof equityCategories
78/// / sizeof equityCategories[0];
79/// @endcode
80/// Category naming is by convention only. In this example, we have chosen a
81/// hierarchical naming convention that uses `.` to separate the constituents
82/// of category names.
83///
84/// In the following, the `addCategory` method is used to define a category for
85/// each of the category names in `equityCategories`. The threshold levels for
86/// each of the categories are set to slightly different values to help
87/// distinguish them when they are printed later. The `addCategory` method
88/// returns the address of the new category:
89/// @code
90/// for (int i = 0; i < NUM_CATEGORIES; ++i) {
91/// int retValue = ball::Administration::addCategory(
92/// equityCategories[i],
93/// ball::Severity::e_TRACE + i,
94/// ball::Severity::e_WARN + i,
95/// ball::Severity::e_ERROR + i,
96/// ball::Severity::e_FATAL + i);
97/// assert(0 == retValue); // added new category
98/// }
99/// @endcode
100/// In the following, each of the new categories is accessed from the registry
101/// and its name and threshold levels are printed to `bsl::cout`:
102/// @code
103/// for (int i = 0; i < NUM_CATEGORIES; ++i) {
104/// const char* name = equityCategories[i];
105/// int recordLevel = ball::Administration::recordLevel(name);
106/// int passLevel = ball::Administration::passLevel(name);
107/// int triggerLevel = ball::Administration::triggerLevel(name);
108/// int triggerAllLevel = ball::Administration::triggerAllLevel(name);
109///
110/// using namespace bsl;
111/// cout << "Category name: " << name << endl;
112/// cout << "\tRecord level: " << recordLevel << endl;
113/// cout << "\tPass level: " << passLevel << endl;
114/// cout << "\tTrigger level: " << triggerLevel << endl;
115/// cout << "\tTrigger-all level: " << triggerAllLevel << endl;
116/// }
117/// @endcode
118/// The following is printed to `stdout`:
119/// @code
120/// Category name: EQUITY.MARKET.NYSE
121/// Record level: 192
122/// Pass level: 96
123/// Trigger level: 64
124/// Trigger-all level: 32
125///
126/// Category name: EQUITY.MARKET.NASDAQ
127/// Record level: 193
128/// Pass level: 97
129/// Trigger level: 65
130/// Trigger-all level: 33
131///
132/// Category name: EQUITY.GRAPHICS.MATH.FACTORIAL
133/// Record level: 194
134/// Pass level: 98
135/// Trigger level: 66
136/// Trigger-all level: 34
137///
138/// Category name: EQUITY.GRAPHICS.MATH.ACKERMANN
139/// Record level: 195
140/// Pass level: 99
141/// Trigger level: 67
142/// Trigger-all level: 35
143/// @endcode
144/// The following is similar to the first `for`-loop above, but this time the
145/// `setThresholdLevels` method is used to modify the threshold levels of
146/// existing categories. The `setThresholdLevels` method returns 1 in each case
147/// indicating the number of existing categories that were affected by the call:
148/// @code
149/// for (int i = 0; i < NUM_CATEGORIES; ++i) {
150/// const int returnValue = ball::Administration::setThresholdLevels(
151/// equityCategories[i],
152/// ball::Severity::e_TRACE - i,
153/// ball::Severity::e_WARN - i,
154/// ball::Severity::e_ERROR - i,
155/// ball::Severity::e_FATAL - i);
156/// assert(1 == returnValue); // modified one category
157/// }
158/// @endcode
159/// When the `NUM_CATEGORIES` categories are accessed from the registry a second
160/// time and printed, the following is output to `stdout` showing the new
161/// threshold levels of the categories:
162/// @code
163/// Category name: EQUITY.MARKET.NYSE
164/// Record level: 192
165/// Pass level: 96
166/// Trigger level: 64
167/// Trigger-all level: 32
168///
169/// Category name: EQUITY.MARKET.NASDAQ
170/// Record level: 191
171/// Pass level: 95
172/// Trigger level: 63
173/// Trigger-all level: 31
174///
175/// Category name: EQUITY.GRAPHICS.MATH.FACTORIAL
176/// Record level: 190
177/// Pass level: 94
178/// Trigger level: 62
179/// Trigger-all level: 30
180///
181/// Category name: EQUITY.GRAPHICS.MATH.ACKERMANN
182/// Record level: 189
183/// Pass level: 93
184/// Trigger level: 61
185/// Trigger-all level: 29
186/// @endcode
187/// Finally, the category registry is closed to further additions by setting its
188/// maximum capacity to (the original) `NUM_CATEGORIES`:
189/// @code
190/// ball::Administration::setMaxNumCategories(NUM_CATEGORIES);
191/// @endcode
192/// Following this call to `setMaxNumCategories`, subsequent calls to
193/// `addCategory` will fail (until such time as `setMaxNumCategories` is called
194/// again with an argument value that is either 0 or is greater than
195/// `NUM_CATEGORIES`, where 0 indicates the category registry has unlimited
196/// capacity).
197/// @}
198/** @} */
199/** @} */
200
201/** @addtogroup bal
202 * @{
203 */
204/** @addtogroup ball
205 * @{
206 */
207/** @addtogroup ball_administration
208 * @{
209 */
210
211#include <balscm_version.h>
212
213
214namespace ball {
215
216 // =====================
217 // struct Administration
218 // =====================
219
220/// This `struct` provides a namespace for a suite of utility functions that
221/// simplifies administration of the `ball` logging subsystem, and insulates
222/// administrative clients from changes to lower-level components of the
223/// `ball` package. A precondition common to all of the utility functions
224/// is that the logger manager singleton must be initialized and not in the
225/// process of being shut down.
226///
227/// See @ref ball_administration
229
230 // CLASS METHODS
231
232 /// Add to the registry of the logger manager singleton a new category
233 /// having the specified `categoryName` and the specified `recordLevel`,
234 /// `passLevel`, `triggerLevel`, and `triggerAllLevel` threshold levels,
235 /// respectively, if (1) `categoryName` is not present in the category
236 /// registry, (2) the number of categories in the registry is less than
237 /// the registry capacity, and (3) each of the level values is in the
238 /// range `[0 .. 255]`. Return 0 on success, and a non-zero value otherwise.
239 ///
240 /// \pre The behavior is undefined unless the logger manager
241 /// singleton has been initialized and is not in the process of being
242 /// shut down.
243 static int addCategory(const char *categoryName,
244 int recordLevel,
245 int passLevel,
246 int triggerLevel,
247 int triggerAllLevel);
248
249 /// Set *both* the default threshold levels and threshold levels of all
250 /// currently existing categories to the specified `recordLevel`,
251 /// `passLevel`, `triggerLevel`, and `triggerAllLevel` values,
252 /// respectively, if each of the level values is in the range
253 /// `[0 .. 255]`. Return 0 on success, and a negative value otherwise
254 /// (with no effect on the default threshold levels).
255 ///
256 /// \pre The behavior is undefined unless the logger manager singleton has been initialized
257 /// and is not in the process of being shut down.
259 int passLevel,
260 int triggerLevel,
261 int triggerAllLevel);
262
263 /// Set the default threshold levels to the specified `recordLevel`,
264 /// `passLevel`, `triggerLevel`, and `triggerAllLevel` values,
265 /// respectively, if each of the level values is in the range
266 /// `[0 .. 255]`. Return 0 on success, and a negative value otherwise
267 /// (with no effect on the default threshold levels).
268 ///
269 /// \pre The behavior is undefined unless the logger manager singleton has been initialized
270 /// and is not in the process of being shut down.
272 int passLevel,
273 int triggerLevel,
274 int triggerAllLevel);
275
276 /// Set the threshold levels of each category currently in the registry
277 /// of the logger manager singleton whose name matches the specified
278 /// `pattern` to the specified `recordLevel`, `passLevel`,
279 /// `triggerLevel`, and `triggerAllLevel` values, respectively, if each
280 /// of the threshold values is in the range `[0 .. 255]`. Return the
281 /// number of categories whose threshold levels were set, and a negative
282 /// value if any of the threshold values were invalid. `pattern` is
283 /// assumed to be of the form "X" or "X*" where X is a sequence of 0 or
284 /// more characters and `*` matches any string (including the empty string).
285 ///
286 /// \pre The behavior is undefined unless the logger manager
287 /// singleton has been initialized and is not in the process of being shut down.
288 ///
289 /// \note Note that only a `*` located at the end of `pattern` is
290 /// recognized as a special character. Also note that this function has
291 /// no effect on the threshold levels of categories added to the
292 /// registry after it is called.
293 static int setThresholdLevels(const char *pattern,
294 int recordLevel,
295 int passLevel,
296 int triggerLevel,
297 int triggerAllLevel);
298
299 /// Reset the default threshold levels to the original "factory-supplied" values.
300 ///
301 /// \pre The behavior is undefined unless the
302 /// logger manager singleton has been initialized and is not in the
303 /// process of being shut down.
305
306 /// Return the record threshold level currently set for the category
307 /// having the specified `categoryName`, and a negative value if no such category exists.
308 ///
309 /// \pre The behavior is undefined unless the logger
310 /// manager singleton has been initialized and is not in the process of
311 /// being shut down.
312 static int recordLevel(const char *categoryName);
313
314 /// Return the pass threshold level currently set for the category
315 /// having the specified `categoryName`, and a negative value if no such category exists.
316 ///
317 /// \pre The behavior is undefined unless the logger
318 /// manager singleton has been initialized and is not in the process of
319 /// being shut down.
320 static int passLevel(const char *categoryName);
321
322 /// Return the trigger threshold level currently set for the category
323 /// having the specified `categoryName`, and a negative value if no such category exists.
324 ///
325 /// \pre The behavior is undefined unless the logger
326 /// manager singleton has been initialized and is not in the process of
327 /// being shut down.
328 static int triggerLevel(const char *categoryName);
329
330 /// Return the trigger-all threshold level currently set for the
331 /// category having the specified `categoryName`, and a negative value if no such category exists.
332 ///
333 /// \pre The behavior is undefined unless the
334 /// logger manager singleton has been initialized and is not in the
335 /// process of being shut down.
336 static int triggerAllLevel(const char *categoryName);
337
338 /// Return the default record threshold level.
339 ///
340 /// \pre The behavior is undefined unless the logger manager singleton has been initialized
341 /// and is not in the process of being shut down.
343
344 /// Return the default pass threshold level.
345 ///
346 /// \pre The behavior is undefined unless the logger manager singleton has been initialized and is not
347 /// in the process of being shut down.
349
350 /// Return the default trigger threshold level.
351 ///
352 /// \pre The behavior is undefined unless the logger manager singleton has been initialized
353 /// and is not in the process of being shut down.
355
356 /// Return the default trigger-all threshold level.
357 ///
358 /// \pre The behavior is undefined unless the logger manager singleton has been initialized
359 /// and is not in the process of being shut down.
361
362 /// Return the current capacity of the registry of the logger manager
363 /// singleton. A capacity of 0 implies no limit will be imposed;
364 /// otherwise, new categories may be added only if
365 /// `numCategories() < maxNumCategories()`.
366 ///
367 /// \pre The behavior is undefined unless the logger manager singleton has been initialized and is not
368 /// in the process of being shut down.
369 ///
370 /// \note Note that `0 < maxNumCategories() < numCategories()` *is* a valid state,
371 /// implying no new categories may be added.
372 static int maxNumCategories();
373
374 /// Return the number of categories in the registry of the logger manager singleton.
375 ///
376 /// \pre The behavior is undefined unless the logger
377 /// manager singleton has been initialized and is not in the process of
378 /// being shut down.
379 static int numCategories();
380
381 /// Set the capacity of the registry of the logger manager singleton to
382 /// the specified `length`. If `length` is 0, no limit will be imposed.
383 /// No categories are removed from the registry if the current number of
384 /// categories exceeds `length`; however, subsequent attempts to add
385 /// categories to the registry will fail.
386 ///
387 /// \pre The behavior is undefined unless the logger manager singleton has been initialized and is not
388 /// in the process of being shut down, and `0 <= length`.
389 static void setMaxNumCategories(int length);
390};
391
392} // close package namespace
393
394
395#endif
396
397// ----------------------------------------------------------------------------
398// Copyright 2015 Bloomberg Finance L.P.
399//
400// Licensed under the Apache License, Version 2.0 (the "License");
401// you may not use this file except in compliance with the License.
402// You may obtain a copy of the License at
403//
404// http://www.apache.org/licenses/LICENSE-2.0
405//
406// Unless required by applicable law or agreed to in writing, software
407// distributed under the License is distributed on an "AS IS" BASIS,
408// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
409// See the License for the specific language governing permissions and
410// limitations under the License.
411// ----------------------------- END-OF-FILE ----------------------------------
412
413/** @} */
414/** @} */
415/** @} */
#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_administration.h:228
static int setAllThresholdLevels(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static int numCategories()
static int setDefaultThresholdLevels(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static int defaultPassThresholdLevel()
static int maxNumCategories()
static void resetDefaultThresholdLevels()
static int triggerLevel(const char *categoryName)
static int addCategory(const char *categoryName, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static int triggerAllLevel(const char *categoryName)
static int defaultRecordThresholdLevel()
static void setMaxNumCategories(int length)
static int defaultTriggerAllThresholdLevel()
static int setThresholdLevels(const char *pattern, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static int recordLevel(const char *categoryName)
static int passLevel(const char *categoryName)
static int defaultTriggerThresholdLevel()