|
BDE 4.39.x Production Release
|
#include <ball_loggermanager.h>
This class is usually a singleton. It provides a factory for Logger objects and is also a wrapper for category administration services.
Public Member Functions | |
| LoggerManager (const LoggerManagerConfiguration &configuration, bslma::Allocator *globalAllocator=0) | |
| ~LoggerManager () | |
| Logger * | allocateLogger (RecordBuffer *buffer) |
| Logger * | allocateLogger (RecordBuffer *buffer, int scratchBufferSize) |
| Logger * | allocateLogger (RecordBuffer *buffer, Observer *observer) |
| Logger * | allocateLogger (RecordBuffer *buffer, int scratchBufferSize, Observer *observer) |
| Logger * | allocateLogger (RecordBuffer *buffer, const bsl::shared_ptr< Observer > &observer) |
| Logger * | allocateLogger (RecordBuffer *buffer, int scratchBufferSize, const bsl::shared_ptr< Observer > &observer) |
| void | deallocateLogger (Logger *logger) |
| Logger & | getLogger () |
| void | setLogger (Logger *logger) |
| Category * | addCategoryHierarchically (const char *categoryName) |
| Category * | addCategory (const char *categoryName, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel) |
| Category & | defaultCategory () |
| Category * | lookupCategory (const char *categoryName) |
| const Category * | setCategory (const char *categoryName) |
| const Category * | setCategory (CategoryHolder *categoryHolder, const char *categoryName) |
| Category * | setCategory (const char *categoryName, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel) |
| void | setMaxNumCategories (int length) |
| void | deregisterAllObservers () |
| int | deregisterObserver (const bsl::string_view &observerName) |
| int | deregisterAttributeCollector (const bsl::string_view &collectorName) |
| bsl::shared_ptr< Observer > | findObserver (const bsl::string_view &observerName) |
| template<class t_OBSERVER > | |
| int | findObserver (bsl::shared_ptr< t_OBSERVER > *result, const bsl::string_view &observerName) |
| Observer * | observer () |
| int | registerObserver (const bsl::shared_ptr< Observer > &observer, const bsl::string_view &observerName) |
| int | registerAttributeCollector (const AttributeCollector &collector, const bsl::string_view &collectorName) |
| void | resetDefaultThresholdLevels () |
| void | setCategoryThresholdsToCurrentDefaults (Category *category) |
| void | setCategoryThresholdsToFactoryDefaults (Category *category) |
| int | setDefaultThresholdLevels (int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel) |
| void | setDefaultThresholdLevelsCallback (DefaultThresholdLevelsCallback *callback) |
| int | setThresholdLevelsHierarchically (const char *categoryNamePrefix, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel) |
| int | addRule (const Rule &value) |
| int | addRules (const RuleSet &ruleSet) |
| void | removeAllRules () |
| int | removeRule (const Rule &value) |
| int | removeRules (const RuleSet &ruleSet) |
| void | publishAll () |
| template<class t_CATEGORY_VISITOR > | |
| void | visitCategories (const t_CATEGORY_VISITOR &visitor) |
| template<class t_OBSERVER_VISITOR > | |
| void | visitObservers (BSLS_COMPILERFEATURES_FORWARD_REF(t_OBSERVER_VISITOR) visitor) |
| bslma::Allocator * | allocator () const |
| const Category & | defaultCategory () const |
| int | defaultPassThresholdLevel () const |
| int | defaultRecordThresholdLevel () const |
| int | defaultTriggerAllThresholdLevel () const |
| int | defaultTriggerThresholdLevel () const |
| bsl::shared_ptr< const Observer > | findObserver (const bsl::string_view &observerName) const |
| template<class t_OBSERVER > | |
| int | findObserver (bsl::shared_ptr< const t_OBSERVER > *result, const bsl::string_view &observerName) const |
| bool | isCategoryEnabled (const Category *category, int severity) const |
| const Category * | lookupCategory (const char *categoryName) const |
| int | maxNumCategories () const |
| int | numCategories () const |
| const Observer * | observer () const |
| const RuleSet & | ruleSet () const |
| const UserFieldsPopulatorCallback * | userFieldsPopulatorCallback () const |
| template<class t_CATEGORY_VISITOR > | |
| void | visitCategories (const t_CATEGORY_VISITOR &visitor) const |
| template<class t_OBSERVER_VISITOR > | |
| void | visitObservers (BSLS_COMPILERFEATURES_FORWARD_REF(t_OBSERVER_VISITOR) visitor) const |
| ThresholdAggregate | defaultThresholdLevels () const |
| int | thresholdLevelsForNewCategory (ThresholdAggregate *levels, const char *categoryName) const |
Friends | |
| class | LoggerManagerCategoryIter |
| class | LoggerManagerCategoryManip |
AttributeCollector is the type of a user-supplied functor used to visit a collection of attributes.
AttributeVisitor is the type of a user-supplied functor invoked by an attribute collector for every attribute.
CategoryNameFilterCallback is the type of the user-supplied functor that translates external category names to internal names.
| typedef CategoryCallbacks::DefaultThresholdLevels ball::LoggerManager::DefaultThresholdLevelsCallback |
DefaultThresholdLevelsCallback is the type of the functor that determines default threshold levels for categories added to the registry by the setCategory(const char *) method.
This typedef is an alias for the type of the internal broadcast observer registry.
PublishAllTriggerCallback is the type of the functor that is invoked to publish all record buffers of all active loggers (i.e., loggers allocated by the logger manager that have not yet been deallocated).
| typedef LoggerManagerConfiguration::UserFieldsPopulatorCallback ball::LoggerManager::UserFieldsPopulatorCallback |
UserFieldsPopulatorCallback is the type of a user-supplied callback functor used to populate the user-defined fields in each log record.
|
explicit |
Create a logger manager having the specified configuration of defaults and attributes. Optionally specify a globalAllocator used to supply memory. If globalAllocator is 0, the currently installed global allocator is used.
| ball::LoggerManager::~LoggerManager | ( | ) |
Destroy this logger manager.
|
inline |
Add to the category registry of this logger manager a new category having the specified categoryName and the specified recordLevel, passLevel, triggerLevel, and triggerAllLevel threshold levels, respectively, if (1) categoryName is not present in the registry, (2) the number of categories in the registry is less than the registry capacity, and (3) each threshold level is in the range [0 .. 255]. Return the address of the new modifiable category on success, and 0 otherwise.
categoryName is null-terminated.
|
inline |
Add a new category having the specified categoryName; return the address of the modifiable new category on success, and 0, with no effect, if a category by that name already exists or if the number of existing categories has reached the maximum capacity. The newly created category will have its threshold levels chosen primarily from two sources: threshold levels of an existing category or a category setting (to which no category exists) choosing the one whose name is the longest non-empty prefix of categoryName. If such a category or setting exists, and the default threshold levels (which might be overridden by a default threshold levels callback) otherwise. See also ball::CategoryManager::addCategoryHierarchically.
|
inline |
Add a rule having the specified value to the set of (unique) rules maintained by this object. Return the number of rules added (i.e., 1 on success and 0 if a rule with the same value is already present).
|
inline |
Add each rule in the specified ruleSet to the set of (unique) rules maintained by this object. Return the number of rules added.
| Logger * ball::LoggerManager::allocateLogger | ( | RecordBuffer * | buffer | ) |
Return the address of a modifiable logger managed by this logger manager configured with the specified record buffer. Optionally specify a scratchBufferSize for the logger's user-accessible message buffer. If scratchBufferSize is not specified, the value configured at construction is used.
buffer is not transferred, and hence, will not be destroyed (or otherwise affected) after the logger is deallocated. | Logger * ball::LoggerManager::allocateLogger | ( | RecordBuffer * | buffer, |
| const bsl::shared_ptr< Observer > & | observer | ||
| ) |
Return the address of a modifiable logger managed by this logger manager having the specified observer that receives published log records and configured with the specified record buffer. Optionally specify a scratchBufferSize for the logger's user-accessible message buffer. If scratchBufferSize is not specified, the value configured at construction is used.
buffer and observer is not transferred, and hence, will not be destroyed (or otherwise affected) after the logger is deallocated. | Logger * ball::LoggerManager::allocateLogger | ( | RecordBuffer * | buffer, |
| int | scratchBufferSize | ||
| ) |
| Logger * ball::LoggerManager::allocateLogger | ( | RecordBuffer * | buffer, |
| int | scratchBufferSize, | ||
| const bsl::shared_ptr< Observer > & | observer | ||
| ) |
| Logger * ball::LoggerManager::allocateLogger | ( | RecordBuffer * | buffer, |
| int | scratchBufferSize, | ||
| Observer * | observer | ||
| ) |
| Logger * ball::LoggerManager::allocateLogger | ( | RecordBuffer * | buffer, |
| Observer * | observer | ||
| ) |
Return the address of a modifiable logger managed by this logger manager having the specified observer that receives published log records and configured with the specified record buffer. Optionally specify a scratchBufferSize for the logger's user-accessible message buffer. If scratchBufferSize is not specified, the value configured at construction is used.
buffer and observer is not transferred, and hence, will not be destroyed (or otherwise affected) after the logger is deallocated.observer, together with the registerObserver method (which takes a shared pointer to an observer), instead.
|
inline |
Return the address of the modifiable allocator held by this logger manager.
|
static |
Create a logger manager that is not the singleton logger manager having the specified configuration of defaults and attributes; load the newly-created logger manager into the specified manager managed pointer. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.
|
static |
Create a logger manager that is not the singleton logger manager having the specified observer that receives published log records and the specified configuration of defaults and attributes; load the newly-created logger manager into the specified manager managed pointer. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.
observer is 0, goes out of scope, or is otherwise destroyed. observer, together with the registerObserver method (which takes a shared pointer to an observer), instead. | void ball::LoggerManager::deallocateLogger | ( | Logger * | logger | ) |
Deallocate the specified logger and release logger from management by this logger manager.
logger was obtained by invoking the allocateLogger method of this logger manager and logger has not yet been deallocated.
|
inline |
Return a non-const reference to the Default Category in the category registry of this logger manager.
|
inline |
Return a const reference to the Default Category in the category registry of this logger manager.
|
inline |
Return the default pass threshold level of this logger manager.
|
inline |
Return the default record threshold level of this logger manager.
|
inline |
Return the default threshold levels associated with this logger manager object.
|
inline |
Return the default trigger-all threshold level of this logger manager.
|
inline |
Return the default trigger threshold level of this logger manager.
|
inline |
Remove all observers from the registry of observers maintained by this logger manager.
|
inline |
Remove the attribute collector having the specified collectorName from the registry of collectors maintained by this logger manager. Return 0 if the collector having collectorName was successfully deregistered from this logger manager, and a non-zero value (with no effect) otherwise.
|
inline |
Remove the observer having the specified observerName from the registry of observers maintained by this logger manager. Return 0 if the observer having observerName was successfully deregistered from this logger manager, and a non-zero value (with no effect) otherwise. Henceforth, the observer that had observerName will no longer receive log records published by this logger manager.
|
inline |
Load into the specified result a shared pointer to the observer of (template parameter) t_OBSERVER type having the specified observerName in the registry of this logger manager, and an empty shared pointer if there is no such observer otherwise. Return 0 if a non-empty shared pointer was loaded, and a non-zero value otherwise.
observerName is in the registry or the observer registered with that name is not of t_OBSERVER type.
|
inline |
Load into the specified result a shared pointer to the observer of (template parameter) t_OBSERVER type having the specified observerName in the registry of this logger manager, and an empty shared pointer if there is no such observer otherwise. Return 0 if a non-empty shared pointer was loaded, and a non-zero value otherwise.
observerName is in the registry or the observer registered with that name is not of t_OBSERVER type.
|
inline |
Return a shared pointer to the observer having the specified observerName in the registry of this logger manager, and an empty shared pointer if there is no such observer otherwise.
|
inline |
Return a shared pointer to the observer having the specified observerName in the registry of this logger manager, and an empty shared pointer if there is no such observer otherwise.
|
inline |
Return a non-const reference to a logger managed by this logger manager suitable for performing logging operations for this thread of execution.
|
static |
Return the address of a modifiable record with the specified fileName and lineNumber attributes, and whose memory is supplied by the currently installed default allocator.
Record must subsequently be supplied to a call to the LoggerManager::logMessage method.
|
static |
Initialize the logger manager singleton. Optionally specify a configuration describing how the singleton should be configured. If configuration is not specified, a default constructed LoggerManagerConfiguration object is used. Optionally specify a globalAllocator used to supply memory. If globalAllocator is 0, the currently installed global allocator is used. Return a non-const reference to the logger manager singleton. This method has no effect (aside from logging a warning) if the logger manager singleton already exists.
|
static |
|
static |
Initialize the logger manager singleton with the specified singleton. Optionally specify an adoptSingleton flag indicating whether this method takes ownership of singleton, in which case shutDownSingleton will destroy singleton. If adoptSingleton is not specified, this method does not take ownership of singleton (and shutDownSingleton will not destroy it). Return 0 if the logger manager singleton was successfully initialized, and a non-zero value otherwise. This method has no effect (aside from logging a warning) if the logger manager singleton already exists, in which case this method does not take ownership of singleton regardless of the value of adoptSingleton.
initSingleton is meant for use only on Windows to initialize another dynamically loaded copy of the LoggerManager system. Also note that a suitable singleton may be obtained by calling createLoggerManager, or from the singleton class method of an already-initialized LoggerManager system.
|
static |
Initialize the logger manager singleton having the specified observer that receives published log records. Optionally specify a configuration describing how the singleton should be configured. If configuration is not specified, a default constructed LoggerManagerConfiguration object is used. Optionally specify a globalAllocator used to supply memory. If globalAllocator is 0, the currently installed global allocator is used. Return a non-const reference to the logger manager singleton. This method has no effect (aside from logging a warning) if the logger manager singleton already exists.
observer is 0, goes out of scope, or is otherwise destroyed.observer, together with the registerObserver method (which takes a shared pointer to an observer), instead.
|
static |
| bool ball::LoggerManager::isCategoryEnabled | ( | const Category * | category, |
| int | severity | ||
| ) | const |
Return true if the specified severity is more severe (i.e., is numerically less than) at least one of the threshold levels of the specified category, and false otherwise. If the returned value is false, then a subsequent call to getLogger().logMessage() (with category and severity) will have no effect. This method compares severity with the threshold levels determined by combining category->thresholdLevels() with the thresholds provided by any relevant and active logging rules (in ruleSet()) that apply to category.
category if the rule's pattern matches category->categoryName(), and a rule is active if all the predicates defined for that rule are satisfied by the current thread's attributes (i.e., Rule::evaluate() returns true for the collection of attributes maintained by the current thread's AttributeContext object).
|
inlinestatic |
Return true if the logger manager singleton exists, and false otherwise.
|
static |
Publish the specified record using bsls::Log::platformDefaultMessageHandler after setting its severity attribute to the specified severity, and dispose of record.
record was obtained by a call to the LoggerManager::getRecord method. record will be invalid after this method returns.
|
inline |
Return the address of the modifiable category in the category registry of this logger manager having the specified categoryName, or 0 if no such category exists.
categoryName is null-terminated.
|
inline |
Return the address of the non-modifiable category in the category registry of this logger manager having the specified categoryName, or 0 if no such category exists.
categoryName is null-terminated.
|
inline |
Return the current capacity of the category registry of this logger manager. A capacity of 0 implies that no limit will be imposed; otherwise, new categories may be added only if numCategories() < maxNumCategories().
0 < maxNumCategories() < numCategories() is a valid state, implying no new categories may be added.
|
inline |
Return the number of categories in the category registry of this logger manager.
| Observer * ball::LoggerManager::observer | ( | ) |
Return the address of the modifiable legacy observer registered with this logger manager.
| const Observer * ball::LoggerManager::observer | ( | ) | const |
Return the address of the non-modifiable observer registered with this logger manager.
|
static |
Block until access to the static buffer used for formatting messages is available. Return the address of the modifiable buffer to which this thread of execution has exclusive access, load the address of the mutex that protects the buffer into the specified *mutex address, and load the size (in bytes) of the buffer into the specified bufferSize address. The address remains valid, and the buffer remains locked by this thread of execution, this thread calls mutex->unlock().
logMessage; other use may adversely affect performance for the entire program.
|
static |
Return a managed pointer that refers to the memory block to which this thread of execution has exclusive access and load the size (in bytes) of this buffer into the specified bufferSize address.
|
inline |
Transmit to the observers registered with this logger manager all log records accumulated in the record buffers of all loggers managed by this logger manager, and indicate the publication cause to be MANUAL_PUBLISH_ALL.
|
inline |
Add the specified collector with the specified collectorName to the registry of attribute collectors maintained by this logger manager. Return 0 if collector was successfully registered with this logger manager, and a non-zero value (with no effect) otherwise.
collectorName is already registered.
|
inline |
Add the specified observer with the specified observerName to the registry of observers maintained by this logger manager. Return 0 if observer was successfully registered with this logger manager, and a non-zero value (with no effect) otherwise. Henceforth, all log records published by this logger manager are published to this observer, until observer is deregistered.
observerName is already registered.
|
inline |
Remove every rule from the set of rules maintained by this object.
|
inline |
Remove the rule having the specified value from this set of rules maintained by this object. Return the number of rules removed (i.e., 1 on success and 0 if no rule having the same value is found.)
|
inline |
Remove each rule in the specified ruleSet from this set of rules maintained by this object. Return the number of rules removed.
|
inline |
Reset the default threshold levels of this logger manager to the original "factory-supplied" default values or the factory overrides supplied at construction.
|
inline |
Return a const reference to the rule set maintained by this object.
|
inline |
Add to the category registry of this logger manager a new category having the specified categoryName and default threshold levels if categoryName is not present in the registry and the number of categories in the registry is less than the registry capacity. Return the address of the (possibly newly-created) non-modifiable category having categoryName, if such a category exists, and the address of the non-modifiable Default Category otherwise. If the specified categoryHolder is non-null, then also load into categoryHolder the returned category and its maximum level and link categoryHolder to the category if it has not yet been linked.
categoryName is null-terminated.
|
inline |
Add to the category registry of this logger manager a new category having the specified categoryName and default threshold levels if categoryName is not present in the registry and the number of categories in the registry is less than the registry capacity. Return the address of the (possibly newly-created) non-modifiable category having categoryName, if such a category exists, and the address of the non-modifiable Default Category otherwise.
categoryName is null-terminated.
|
inline |
Add to the category registry of this logger manager a new category having the specified categoryName and recordLevel, passLevel, triggerLevel, and triggerAllLevel threshold levels, respectively, if (1) categoryName is not present in the registry, (2) the number of categories in the registry is less than the registry capacity, and (3) recordLevel, passLevel, triggerLevel, and triggerAllLevel are all within the range [0 .. 255]. If categoryName is already present and each threshold level is within the valid range then reset the threshold levels of categoryName to the specified values. Return the address of the (possibly newly-created) modifiable category having categoryName if categoryName was either created or its thresholds reset, and 0 otherwise.
categoryName is null-terminated.
|
inline |
Set the threshold levels of the specified category in the category registry of this logger manager to the current default threshold values.
category is non-null.
|
inline |
Set the threshold levels of the specified category in the category registry of this logger manager to the original "factory-supplied" default values or the factory overrides supplied at construction.
category is non-null.
|
inline |
Set the default threshold levels of this logger manager to the specified recordLevel, passLevel, triggerLevel, and triggerAllLevel values, respectively, if each threshold level is in the range [0 .. 255]. Return 0 on success, and a non-zero value otherwise (with no effect on any default threshold level).
|
inline |
Set the default-thresholds callback of this logger manager to the specified callback. The default-thresholds callback is used to determine default threshold levels for categories added to the registry by the setCategory(const char *) method.
| void ball::LoggerManager::setLogger | ( | Logger * | logger | ) |
Set the default logger used by this thread of execution to the specified logger, or to the global default logger if logger is 0.
logger was obtained from this logger manager, and this thread of execution does not hold exclusive access to the record buffer of its current default logger.
|
inline |
Set the capacity of the category registry of this logger manager to the specified length. If length is 0, no limit will be imposed. No categories are removed from the registry if the current number of categories exceeds length. However, subsequent attempts to add categories to the registry will fail.
0 <= length.
|
inline |
In case the specified categoryNamePrefix is not empty set the threshold levels of every existing and future category whose name has, as a prefix, categoryNamePrefix to the specified threshold values, recordLevel, passLevel, triggerLevel, and triggerAllLevel. In case categoryNamePrefix is empty set the threshold level of every existing category, and remove all preliminary settings (for future categories). Return the number of categories whose threshold levels were set, or a negative value, with no effect, if any of the specified threshold values is outside the range [0 .. 255]. See also ball::CategoryManager::setThresholdLevelsHierarchically.
|
static |
Destroy the logger manager singleton and release all resources used by it. This method has no effect if the logger manager singleton does not exist (i.e., it has not been initialized or has already been destroyed).
|
inlinestatic |
Return a non-const reference to the logger manager singleton.
|
inline |
Load into the specified *levels the threshold levels that would be set for a newly created category, irrespective of whether a category with the specified categoryName is already in the registry. Return 0 on success and a non-zero value otherwise. If the client has configured a default threshold levels callback (see ball::LoggerManager::DefaultThresholdLevelsCallback in the component doc), the categoryName will be supplied to that callback which will set *levels. Otherwise, if no default threshold levels callback has been provided, the default threshold levels are used.
categoryName is already in the registry, the levels returned by this method may differ from the levels of that category. | const UserFieldsPopulatorCallback * ball::LoggerManager::userFieldsPopulatorCallback | ( | ) | const |
Return the address of the non-modifiable user populator functor registered with this logger manager, or 0 if there is no registered user populator functor.
|
inline |
Invoke the specified visitor functor on each category managed by this object, providing that functor modifiable access to each category. visitor must be a functor that can be called as if it had the following signature:
|
inline |
Invoke the specified visitor functor on each category managed by this object, providing that functor non-modifiable access to each category. visitor must be a functor that can be called as if it had the following signature:
|
inline |
Invoke the specified visitor functor of (template parameter) t_OBSERVER_VISITOR type on each element in the registry of this logger manager, supplying that functor modifiable access to each observer. visitor must be a functor that can be called as if it had the following signature:
|
inline |
Invoke the specified visitor functor of (template parameter) t_OBSERVER_VISITOR type on each element in the registry of this logger manager, supplying that functor modifiable access to each observer. visitor must be a functor that can be called as if it had the following signature:
|
friend |
|
friend |