BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball_loggermanagerdefaults.h
Go to the documentation of this file.
1/// @file ball_loggermanagerdefaults.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_loggermanagerdefaults.h -*-C++-*-
8#ifndef INCLUDED_BALL_LOGGERMANAGERDEFAULTS
9#define INCLUDED_BALL_LOGGERMANAGERDEFAULTS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_loggermanagerdefaults ball_loggermanagerdefaults
15/// @brief Provide constrained default attributes for the logger manager.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_loggermanagerdefaults
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_loggermanagerdefaults-purpose"> Purpose</a>
25/// * <a href="#ball_loggermanagerdefaults-classes"> Classes </a>
26/// * <a href="#ball_loggermanagerdefaults-description"> Description </a>
27/// * <a href="#ball_loggermanagerdefaults-thread-safety"> Thread Safety </a>
28/// * <a href="#ball_loggermanagerdefaults-design-note"> Design Note </a>
29/// * <a href="#ball_loggermanagerdefaults-usage"> Usage </a>
30/// * <a href="#ball_loggermanagerdefaults-example-1-basic-usage"> Example 1: Basic Usage </a>
31///
32/// # Purpose {#ball_loggermanagerdefaults-purpose}
33/// Provide constrained default attributes for the logger manager.
34///
35/// # Classes {#ball_loggermanagerdefaults-classes}
36///
37/// - ball::LoggerManagerDefaults: default parameters for logger manager
38///
39/// @see ball_loggermanagerconfiguration
40///
41/// # Description {#ball_loggermanagerdefaults-description}
42/// This component provides a simply-constrained attribute class,
43/// `ball::LoggerManagerDefaults`, that contains a set of attributes (objects
44/// and parameters) of particular use to logger managers. The constraints are
45/// actively maintained by the class. In particular, the "set" methods for
46/// constrained values will fail if their arguments are not consistent with the
47/// constraints. Also, the constructor does not take any constrained arguments,
48/// but rather sets those values to valid defaults unconditionally. This
49/// behavior avoids "silent failures", since the constructor cannot explicitly
50/// return a status value.
51///
52/// The attributes contained by a `ball::LoggerManagerDefaults` object and
53/// the attribute constraints are given, respectively, in two tables below.
54/// The attributes are as follows:
55/// @code
56/// TYPE NAME DESCRIPTION
57/// ----------- ---------------- -------------------------------------
58/// int recordBufferSize size in bytes of *default* logger's
59/// record buffer
60/// int loggerBufferSize default size in bytes of *each*
61/// logger's "scratch" buffer (for macros)
62/// char recordLevel default record severity level
63/// char passLevel default pass-through severity level
64/// char triggerLevel default trigger severity level
65/// char triggerAllLevel default triggerAll severity level
66/// @endcode
67/// The constraints are as follows:
68/// @code
69/// NAME CONSTRAINT
70/// +--------------------+---------------------------------------------+
71/// | recordBufferSize | 1 <= recordBufferSize |
72/// +--------------------+---------------------------------------------+
73/// | loggerBufferSize | 1 <= loggerBufferSize |
74/// +--------------------+---------------------------------------------+
75/// | recordLevel | 0 <= recordLevel <= 255 |
76/// | passLevel | 0 <= passLevel <= 255 |
77/// | triggerLevel | 0 <= triggerLevel <= 255 |
78/// | triggerAllLevel | 0 <= triggerAllLevel <= 255 |
79/// +--------------------+---------------------------------------------+
80/// @endcode
81/// Although the numerical constraints on the four severity levels are
82/// independent of one another, they are treated as logically coupled, and must
83/// be set as a group. If any one value cannot be successfully set, then the
84/// whole set operation fails with no effect on the object value. This may be
85/// viewed as an auxiliary constraint.
86///
87/// ## Thread Safety {#ball_loggermanagerdefaults-thread-safety}
88///
89///
90/// This constrained-attribute component is *thread-safe* but not
91/// *thread-enabled*, and requires explicit synchronization in the user space.
92///
93/// ## Design Note {#ball_loggermanagerdefaults-design-note}
94///
95///
96/// This component provides a BDE constrained-attribute type designed to be
97/// *useful* to `ball::LoggerManager`. However, `ball::LoggerManagerDefaults`
98/// is not `ball::LoggerManagerConfiguration`, the actual configuration object
99/// used by the logger manager. `ball::LoggerManagerConfiguration` is not a
100/// value semantic type, because it holds functors.
101/// `ball::LoggerManagerDefaults`, which is used by
102/// `ball::LoggerManagerConfiguration`, may be regarded as a factored detail of
103/// the actual configuration object.
104///
105/// ## Usage {#ball_loggermanagerdefaults-usage}
106///
107///
108/// This section illustrates intended use of this component.
109///
110/// ### Example 1: Basic Usage {#ball_loggermanagerdefaults-example-1-basic-usage}
111///
112///
113/// The following snippets of code illustrate how to use a
114/// `ball::LoggerManagerDefaults` object. First, create a configuration object
115/// `lmd`. Note that it is necessarily configured to valid but unpublished
116/// defaults.
117/// @code
118/// ball::LoggerManagerDefaults lmd;
119/// @endcode
120/// Next, set each attribute. Note that the four severity threshold levels must
121/// be set atomically (i.e., with a single four-argument "set" method). Note
122/// also that each "set" method will fail if the argument or set of arguments is
123/// not valid, and so each method returns a status value.
124/// @code
125/// assert( 0 == lmd.setDefaultRecordBufferSizeIfValid(32768));
126/// assert(32768 == lmd.defaultRecordBufferSize());
127///
128/// assert( 0 == lmd.setDefaultLoggerBufferSizeIfValid(2048));
129/// assert(2048 == lmd.defaultLoggerBufferSize());
130///
131/// assert( 0 == lmd.setDefaultThresholdLevelsIfValid(192, 64, 48, 32));
132/// assert(192 == lmd.defaultRecordLevel());
133/// assert( 64 == lmd.defaultPassLevel());
134/// assert( 48 == lmd.defaultTriggerLevel());
135/// assert( 32 == lmd.defaultTriggerAllLevel());
136/// @endcode
137/// The configuration object is now validly configured with our choice of
138/// parameters. If, however, we attempt to set an invalid configuration, the
139/// "set" method will fail (with a non-zero return status), and the
140/// configuration will be left unchanged.
141/// @code
142/// assert( 0 != lmd.setDefaultThresholdLevelsIfValid(256, 90, 60, 30));
143/// assert(192 == lmd.defaultRecordLevel());
144/// assert( 64 == lmd.defaultPassLevel());
145/// assert( 48 == lmd.defaultTriggerLevel());
146/// assert( 32 == lmd.defaultTriggerAllLevel());
147/// @endcode
148/// Finally, we can print the configuration value to `stdout`.
149/// @code
150/// bsl::cout << lmd << bsl::endl;
151/// @endcode
152/// This produces the following (multi-line) output:
153/// @code
154/// [
155/// recordBufferSize : 32768
156/// loggerBufferSize : 2048
157/// recordLevel : 192
158/// passLevel : 64
159/// triggerLevel : 48
160/// triggerAllLevel : 32
161/// ]
162/// @endcode
163/// @}
164/** @} */
165/** @} */
166
167/** @addtogroup bal
168 * @{
169 */
170/** @addtogroup ball
171 * @{
172 */
173/** @addtogroup ball_loggermanagerdefaults
174 * @{
175 */
176
177#include <balscm_version.h>
178
179#include <bsl_iosfwd.h>
180
181
182namespace ball {
183
184 // ===========================
185 // class LoggerManagerDefaults
186 // ===========================
187
188/// This class provides constrained configuration parameters for a logger
189/// manager. The constraints are maintained as class invariants; it is not
190/// possible to obtain an invalid object through this interface.
191///
192/// More generally, this class supports a complete set of *value* *semantic*
193/// operations, including copy construction, assignment, equality
194/// comparison, `ostream` printing. (A precise operational definition of
195/// when two instances have the same value can be found in the description
196/// of `operator==` for the class.) This class is *exception* *neutral*
197/// with no guarantee of rollback: if an exception is thrown during the
198/// invocation of a method on a pre-existing instance, the object is left in
199/// a valid state, but its value is undefined. In no event is memory
200/// leaked. Finally, *aliasing* (e.g., using all or part of an object as
201/// both source and destination) is supported in all cases.
202///
203/// See @ref ball_loggermanagerdefaults
205
206 private:
207 // DATA
208 int d_recordBufferSize; // size of default logger's record buffer
209 int d_loggerBufferSize; // size of logger "scratchpad" buffer (for macros)
210
211 int d_defaultRecordLevel;
212 int d_defaultPassLevel;
213 int d_defaultTriggerLevel;
214
215 // constrained set of default threshold levels for logger manager
216 int d_defaultTriggerAllLevel;
217
218 // FRIENDS
219 friend bsl::ostream& operator<<(bsl::ostream&,
220 const LoggerManagerDefaults&);
222 const LoggerManagerDefaults&);
223
224 public:
225 // CLASS METHODS
226
227 /// Return `true` if the specified `numBytes` is a valid default-logger
228 /// record-buffer size attribute, and `false` otherwise. `numBytes` is
229 /// valid if 0 < numBytes.
230 static bool isValidDefaultRecordBufferSize(int numBytes);
231
232 /// Return `true` if the specified `numBytes` is a valid default
233 /// logger-message-buffer size attribute, and `false` otherwise.
234 /// `numBytes` is valid if 0 < numBytes.
235 static bool isValidDefaultLoggerBufferSize(int numBytes);
236
237 /// Return `true` if each of the specified `recordLevel`, `passLevel`,
238 /// `triggerLevel`, and `triggerAllLevel` values is a valid default
239 /// severity threshold level attributes, and `false` otherwise. Valid
240 /// severity threshold level values are in the range `[0 .. 255]`.
241 static bool areValidDefaultThresholdLevels(int recordLevel,
242 int passLevel,
243 int triggerLevel,
244 int triggerAllLevel);
245
246 /// Return the implementation-defined default-logger record-buffer size
247 /// value for this class.
249
250 /// Return the implementation-defined default logger-message-buffer size
251 /// value for this class.
253
254 /// Return the implementation-defined default record threshold level
255 /// value for this class.
257
258 /// Return the implementation-defined default pass threshold level value
259 /// for this class.
261
262 /// Return the implementation-defined default trigger threshold level
263 /// value for this class.
265
266 /// Return the implementation-defined default trigger-all threshold
267 /// value for this class.
269
270 // CREATORS
271
272 /// Create a logger manager default-values constrained-attribute object
273 /// having valid default values for all attributes.
275
276 /// Create a logger manager default-values constrained-attribute object
277 /// having the value of the specified `original` object.
279
280 /// Destroy this logger manager default-values constrained-attribute
281 /// object.
283
284 // MANIPULATORS
285
286 /// Assign to this logger manager default-values constrained-attribute
287 /// object the value of the specified `rhs` object.
289
290 /// Set the default-logger record-buffer size attribute of this object
291 /// to the specified `numBytes` if 0 < numBytes. Return 0 on success,
292 /// and a non-zero value (with no effect on the state of this object)
293 /// otherwise.
295
296 /// Set the default logger-message-buffer size attribute of this object
297 /// to the specified `numBytes` if 0 < numBytes. Return 0 on success,
298 /// and a non-zero value (with no effect on the state of this object)
299 /// otherwise.
301
302 /// Set the pass-through severity threshold level attribute of the
303 /// `LoggerManagerDefaults` attribute of this object to the
304 /// specified `passLevel`, if it is in the range `[0 .. 255]`, and set
305 /// all the other threshold levels (recordLevel, triggerLevel,
306 /// triggerAllLevel) to 0. Return 0 on success, and a non-zero value
307 /// otherwise with no effect on this object.
309
310 /// Set the quadruplet of default severity threshold level attributes of
311 /// this object to the specified `recordLevel`, `passLevel`,
312 /// `triggerLevel`, and `triggerAllLevel` values if each level is in the
313 /// range `[0 .. 255]`. Return 0 on success, and a non-zero value (with
314 /// no effect on the state of this object) otherwise.
316 int passLevel,
317 int triggerLevel,
318 int triggerAllLevel);
319
320 // ACCESSORS
321
322 /// Return the default-logger record-buffer size attribute of this
323 /// object.
325
326 /// Return the default logger-message-buffer size attribute of this
327 /// object.
329
330 /// Return the default record threshold level attribute of this object.
332
333 /// Return the default pass threshold level attribute of this object.
334 int defaultPassLevel() const;
335
336 /// Return the default trigger threshold level attribute of this object.
338
339 /// Return the default trigger-all threshold level attribute of this
340 /// object.
342
343 /// Format this object to the specified output `stream` at the (absolute
344 /// value of) the optionally specified indentation `level` and return a
345 /// reference to `stream`. If `level` is specified, optionally specify
346 /// `spacesPerLevel`, the number of spaces per indentation level for
347 /// this and all of its nested objects. If `level` is negative,
348 /// suppress indentation of the first line. If `spacesPerLevel` is
349 /// negative, suppress all indentation AND format the entire output on
350 /// one line. If `stream` is not valid on entry, this operation has no
351 /// effect.
352 bsl::ostream& print(bsl::ostream& stream,
353 int level = 0,
354 int spacesPerLevel = 4) const;
355};
356
357// FREE OPERATORS
358
359/// Return `true` if the specified `lhs` and `rhs` attribute objects have
360/// the same value, and `false` otherwise. Two attribute objects objects
361/// have the same value if each respective attribute has the same value.
362bool operator==(const LoggerManagerDefaults& lhs,
363 const LoggerManagerDefaults& rhs);
364
365/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
366/// have the same value, and `false` otherwise. Two attribute objects do
367/// not have the same value if one or more respective attributes differ in
368/// values.
369bool operator!=(const LoggerManagerDefaults& lhs,
370 const LoggerManagerDefaults& rhs);
371
372/// Write the specified `defaults` object to the specified output `stream`
373/// in a reasonable multi-line format.
374bsl::ostream& operator<<(bsl::ostream& stream,
375 const LoggerManagerDefaults& defaults);
376
377} // close package namespace
378
379
380#endif
381
382// ----------------------------------------------------------------------------
383// Copyright 2015 Bloomberg Finance L.P.
384//
385// Licensed under the Apache License, Version 2.0 (the "License");
386// you may not use this file except in compliance with the License.
387// You may obtain a copy of the License at
388//
389// http://www.apache.org/licenses/LICENSE-2.0
390//
391// Unless required by applicable law or agreed to in writing, software
392// distributed under the License is distributed on an "AS IS" BASIS,
393// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
394// See the License for the specific language governing permissions and
395// limitations under the License.
396// ----------------------------- END-OF-FILE ----------------------------------
397
398/** @} */
399/** @} */
400/** @} */
Definition ball_loggermanagerdefaults.h:204
int defaultTriggerAllLevel() const
friend bsl::ostream & operator<<(bsl::ostream &, const LoggerManagerDefaults &)
friend bool operator==(const LoggerManagerDefaults &, const LoggerManagerDefaults &)
int setDefaultLoggerBufferSizeIfValid(int numBytes)
int setDefaultThresholdLevelsIfValid(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static int defaultDefaultTriggerLevel()
LoggerManagerDefaults(const LoggerManagerDefaults &original)
int defaultLoggerBufferSize() const
static bool areValidDefaultThresholdLevels(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
int defaultRecordBufferSize() const
static int defaultDefaultRecordLevel()
static bool isValidDefaultLoggerBufferSize(int numBytes)
int defaultPassLevel() const
Return the default pass threshold level attribute of this object.
static int defaultDefaultPassLevel()
static int defaultDefaultLoggerBufferSize()
LoggerManagerDefaults & operator=(const LoggerManagerDefaults &rhs)
int defaultTriggerLevel() const
Return the default trigger threshold level attribute of this object.
int defaultRecordLevel() const
Return the default record threshold level attribute of this object.
static int defaultDefaultTriggerAllLevel()
int setDefaultThresholdLevelsIfValid(int passLevel)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
static int defaultDefaultRecordBufferSize()
int setDefaultRecordBufferSizeIfValid(int numBytes)
static bool isValidDefaultRecordBufferSize(int numBytes)
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition ball_administration.h:214
bsl::ostream & operator<<(bsl::ostream &output, const Attribute &attribute)