Class CompositeLogger

java.lang.Object
org.pipservices3.components.log.Logger
org.pipservices3.components.log.CompositeLogger
All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.config.IReconfigurable, org.pipservices3.commons.refer.IReferenceable, ILogger

public class CompositeLogger
extends Logger
Aggregates all loggers from component references under a single component.

It allows to log messages and conveniently send them to multiple destinations.

### References ###

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages

### Example ###

 
 class MyComponent implements IConfigurable, IReferenceable {
     CompositeLogger _logger = new CompositeLogger();
 
     public void configure(ConfigParams config) {
        this._logger.configure(config);
        ...
     }
 
     public void setReferences(IReferences references) {
         this._logger.setReferences(references);
         ...
     }
 
     public void myMethod(String correlationId) {
         this._logger.debug(correlationId, "Called method mycomponent.mymethod");
         ...
     }
 }
 
 
See Also:
ILogger
  • Constructor Details

    • CompositeLogger

      public CompositeLogger()
      Creates a new instance of the logger.
    • CompositeLogger

      public CompositeLogger​(org.pipservices3.commons.refer.IReferences references) throws org.pipservices3.commons.refer.ReferenceException
      Creates a new instance of the logger.
      Parameters:
      references - references to locate the component dependencies.
      Throws:
      org.pipservices3.commons.refer.ReferenceException - when no references found
  • Method Details

    • setReferences

      public void setReferences​(org.pipservices3.commons.refer.IReferences references)
      Sets references to dependent components.
      Specified by:
      setReferences in interface org.pipservices3.commons.refer.IReferenceable
      Overrides:
      setReferences in class Logger
      Parameters:
      references - references to locate the component dependencies.
    • write

      protected void write​(LogLevel level, String correlationId, Exception error, String message)
      Writes a log message to the logger destination(s).
      Specified by:
      write in class Logger
      Parameters:
      level - a log level.
      correlationId - (optional) transaction id to trace execution through call chain.
      error - an error object associated with this message.
      message - a human-readable message to log.