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, correlation_id: Optional[str], error: Optional[Exception], message: Optional[str])
- level: LogLevel - a log level.
- correlation_id: Optional[str] - (optional) transaction id to trace execution through 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, correlation_id):
self.__logger.debug(correlation_id, "Called method mycomponent.mymethod")