BDE 4.14.0 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.
227
228 // CLASS METHODS
229
230 /// Add to the registry of the logger manager singleton a new category
231 /// having the specified `categoryName` and the specified `recordLevel`,
232 /// `passLevel`, `triggerLevel`, and `triggerAllLevel` threshold levels,
233 /// respectively, if (1) `categoryName` is not present in the category
234 /// registry, (2) the number of categories in the registry is less than
235 /// the registry capacity, and (3) each of the level values is in the
236 /// range `[0 .. 255]`. Return 0 on success, and a non-zero value
237 /// otherwise. The behavior is undefined unless the logger manager
238 /// singleton has been initialized and is not in the process of being
239 /// shut down.
240 static int addCategory(const char *categoryName,
241 int recordLevel,
242 int passLevel,
243 int triggerLevel,
244 int triggerAllLevel);
245
246 /// Set *both* the default threshold levels and threshold levels of all
247 /// currently existing categories to the specified `recordLevel`,
248 /// `passLevel`, `triggerLevel`, and `triggerAllLevel` values,
249 /// respectively, if each of the level values is in the range
250 /// `[0 .. 255]`. Return 0 on success, and a negative value otherwise
251 /// (with no effect on the default threshold levels). The behavior is
252 /// undefined unless the logger manager singleton has been initialized
253 /// and is not in the process of being shut down.
255 int passLevel,
256 int triggerLevel,
257 int triggerAllLevel);
258
259 /// Set the default threshold levels to the specified `recordLevel`,
260 /// `passLevel`, `triggerLevel`, and `triggerAllLevel` values,
261 /// respectively, if each of the level values is in the range
262 /// `[0 .. 255]`. Return 0 on success, and a negative value otherwise
263 /// (with no effect on the default threshold levels). The behavior is
264 /// undefined unless the logger manager singleton has been initialized
265 /// and is not in the process of being shut down.
267 int passLevel,
268 int triggerLevel,
269 int triggerAllLevel);
270
271 /// Set the threshold levels of each category currently in the registry
272 /// of the logger manager singleton whose name matches the specified
273 /// `pattern` to the specified `recordLevel`, `passLevel`,
274 /// `triggerLevel`, and `triggerAllLevel` values, respectively, if each
275 /// of the threshold values is in the range `[0 .. 255]`. Return the
276 /// number of categories whose threshold levels were set, and a negative
277 /// value if any of the threshold values were invalid. `pattern` is
278 /// assumed to be of the form "X" or "X*" where X is a sequence of 0 or
279 /// more characters and `*` matches any string (including the empty
280 /// string). The behavior is undefined unless the logger manager
281 /// singleton has been initialized and is not in the process of being
282 /// shut down. Note that only a `*` located at the end of `pattern` is
283 /// recognized as a special character. Also note that this function has
284 /// no effect on the threshold levels of categories added to the
285 /// registry after it is called.
286 static int setThresholdLevels(const char *pattern,
287 int recordLevel,
288 int passLevel,
289 int triggerLevel,
290 int triggerAllLevel);
291
292 /// Reset the default threshold levels to the original
293 /// "factory-supplied" values. The behavior is undefined unless the
294 /// logger manager singleton has been initialized and is not in the
295 /// process of being shut down.
297
298 /// Return the record threshold level currently set for the category
299 /// having the specified `categoryName`, and a negative value if no such
300 /// category exists. The behavior is undefined unless the logger
301 /// manager singleton has been initialized and is not in the process of
302 /// being shut down.
303 static int recordLevel(const char *categoryName);
304
305 /// Return the pass threshold level currently set for the category
306 /// having the specified `categoryName`, and a negative value if no such
307 /// category exists. The behavior is undefined unless the logger
308 /// manager singleton has been initialized and is not in the process of
309 /// being shut down.
310 static int passLevel(const char *categoryName);
311
312 /// Return the trigger threshold level currently set for the category
313 /// having the specified `categoryName`, and a negative value if no such
314 /// category exists. The behavior is undefined unless the logger
315 /// manager singleton has been initialized and is not in the process of
316 /// being shut down.
317 static int triggerLevel(const char *categoryName);
318
319 /// Return the trigger-all threshold level currently set for the
320 /// category having the specified `categoryName`, and a negative value
321 /// if no such category exists. The behavior is undefined unless the
322 /// logger manager singleton has been initialized and is not in the
323 /// process of being shut down.
324 static int triggerAllLevel(const char *categoryName);
325
326 /// Return the default record threshold level. The behavior is
327 /// undefined unless the logger manager singleton has been initialized
328 /// and is not in the process of being shut down.
330
331 /// Return the default pass threshold level. The behavior is undefined
332 /// unless the logger manager singleton has been initialized and is not
333 /// in the process of being shut down.
335
336 /// Return the default trigger threshold level. The behavior is
337 /// undefined unless the logger manager singleton has been initialized
338 /// and is not in the process of being shut down.
340
341 /// Return the default trigger-all threshold level. The behavior is
342 /// undefined unless the logger manager singleton has been initialized
343 /// and is not in the process of being shut down.
345
346 /// Return the current capacity of the registry of the logger manager
347 /// singleton. A capacity of 0 implies no limit will be imposed;
348 /// otherwise, new categories may be added only if
349 /// `numCategories() < maxNumCategories()`. The behavior is undefined
350 /// unless the logger manager singleton has been initialized and is not
351 /// in the process of being shut down. Note that
352 /// `0 < maxNumCategories() < numCategories()` *is* a valid state,
353 /// implying no new categories may be added.
354 static int maxNumCategories();
355
356 /// Return the number of categories in the registry of the logger
357 /// manager singleton. The behavior is undefined unless the logger
358 /// manager singleton has been initialized and is not in the process of
359 /// being shut down.
360 static int numCategories();
361
362 /// Set the capacity of the registry of the logger manager singleton to
363 /// the specified `length`. If `length` is 0, no limit will be imposed.
364 /// No categories are removed from the registry if the current number of
365 /// categories exceeds `length`; however, subsequent attempts to add
366 /// categories to the registry will fail. The behavior is undefined
367 /// unless the logger manager singleton has been initialized and is not
368 /// in the process of being shut down, and `0 <= length`.
369 static void setMaxNumCategories(int length);
370};
371
372} // close package namespace
373
374
375#endif
376
377// ----------------------------------------------------------------------------
378// Copyright 2015 Bloomberg Finance L.P.
379//
380// Licensed under the Apache License, Version 2.0 (the "License");
381// you may not use this file except in compliance with the License.
382// You may obtain a copy of the License at
383//
384// http://www.apache.org/licenses/LICENSE-2.0
385//
386// Unless required by applicable law or agreed to in writing, software
387// distributed under the License is distributed on an "AS IS" BASIS,
388// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
389// See the License for the specific language governing permissions and
390// limitations under the License.
391// ----------------------------- END-OF-FILE ----------------------------------
392
393/** @} */
394/** @} */
395/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition ball_administration.h:214
Definition ball_administration.h:226
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()