Aggregates all loggers from component references under a single component.
Implements: Logger, IReferenceable
Description
The CompositeLogger class allows you to aggregate loggers from component references into a single component.
Important points
- It allows to log messages and conveniently send them to multiple destinations.
References
- *:logger:*:*:1.0 - (optional) ILogger components to pass log messages
Constructors
Creates a new instance of the logger.
CompositeLogger(references: IReferences = None)
- references: IReferences - references to locate the component dependencies.
Instance methods
set_references
Sets references to dependent components.
set_references(references: IReferences)
- references: IReferences - references to locate the component dependencies.
_write
Writes a log message to the logger destination.
_write(level: LogLevel, context: Optional[IContext], error: Optional[Exception], message: Optional[str])
- level: LogLevel - a log level.
- context: IContext - (optional) a context to trace execution through a call chain.
- error: Optional[Exception] - an error object associated with this message.
- message: Optional[str] - a human-readable message to log.
Examples
class MyComponent(IConfigurable, IReferenceable):
__logger = CompositeLogger()
def configure(self, config):
self.__logger.configure(config)
def set_references(self, references):
self.__logger.set_references(references)
def my_method(self, context):
self.__logger.debug(context, "Called method mycomponent.mymethod")