Class Logger

java.lang.Object
org.pipservices3.components.log.Logger
All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.config.IReconfigurable, org.pipservices3.commons.refer.IReferenceable, ILogger
Direct Known Subclasses:
CachedLogger, CompositeLogger, ConsoleLogger, DiagnosticsLogger

public abstract class Logger
extends Object
implements ILogger, org.pipservices3.commons.config.IReconfigurable, org.pipservices3.commons.refer.IReferenceable
Abstract logger that captures and formats log messages. Child classes take the captured messages and write them to their specific destinations.

### Configuration parameters ###

Parameters to pass to the configure() method for component configuration:

  • level: maximum log level to capture
  • source: source (context) name

### References ###

  • *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source
See Also:
ILogger
  • Field Details

    • _source

      protected String _source
  • Constructor Details

    • Logger

      protected Logger()
      Creates a new instance of the logger.
  • Method Details

    • configure

      public void configure​(org.pipservices3.commons.config.ConfigParams config)
      Configures component by passing configuration parameters.
      Specified by:
      configure in interface org.pipservices3.commons.config.IConfigurable
      Parameters:
      config - configuration parameters to be set.
    • 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
      Parameters:
      references - references to locate the component dependencies.
    • composeError

      protected String composeError​(Exception error)
      Composes an human-readable error description
      Parameters:
      error - an error to format.
      Returns:
      a human-reable error description.
    • getLevel

      public LogLevel getLevel()
      Gets the maximum log level. Messages with higher log level are filtered out.
      Specified by:
      getLevel in interface ILogger
      Returns:
      the maximum log level.
    • setLevel

      public void setLevel​(LogLevel value)
      Set the maximum log level.
      Specified by:
      setLevel in interface ILogger
      Parameters:
      value - a new maximum log level.
    • write

      protected abstract void write​(LogLevel level, String correlationId, Exception error, String message)
      Writes a log message to the logger destination.
      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.
    • formatAndWrite

      protected void formatAndWrite​(LogLevel level, String correlationId, Exception error, String message, Object[] args)
      Formats the log message and writes it to the logger destination.
      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.
      args - arguments to parameterize the message.
    • log

      public void log​(LogLevel level, String correlationId, Exception error, String message, Object... args)
      Logs a message at specified log level.
      Specified by:
      log in interface ILogger
      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.
      args - arguments to parameterize the message.
    • fatal

      public void fatal​(String correlationId, String message, Object... args)
      Logs fatal (unrecoverable) message that caused the process to crash.
      Specified by:
      fatal in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      message - a human-readable message to log.
      args - arguments to parameterize the message.
    • fatal

      public void fatal​(String correlationId, Exception error)
      Logs fatal (unrecoverable) message that caused the process to crash.
      Specified by:
      fatal in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      error - an error object associated with this message.
    • fatal

      public void fatal​(String correlationId, Exception error, String message, Object... args)
      Logs fatal (unrecoverable) message that caused the process to crash.
      Specified by:
      fatal in interface ILogger
      Parameters:
      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.
      args - arguments to parameterize the message.
    • error

      public void error​(String correlationId, String message, Object... args)
      Logs recoverable application error.
      Specified by:
      error in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      message - a human-readable message to log.
      args - arguments to parameterize the message.
    • error

      public void error​(String correlationId, Exception error)
      Logs recoverable application error.
      Specified by:
      error in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      error - an error object associated with this message.
    • error

      public void error​(String correlationId, Exception error, String message, Object... args)
      Logs recoverable application error.
      Specified by:
      error in interface ILogger
      Parameters:
      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.
      args - arguments to parameterize the message.
    • warn

      public void warn​(String correlationId, String message, Object... args)
      Logs a warning that may or may not have a negative impact.
      Specified by:
      warn in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      message - a human-readable message to log.
      args - arguments to parameterize the message.
    • info

      public void info​(String correlationId, String message, Object... args)
      Logs an important information message
      Specified by:
      info in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      message - a human-readable message to log.
      args - arguments to parameterize the message.
    • debug

      public void debug​(String correlationId, String message, Object... args)
      Logs a high-level debug information for troubleshooting.
      Specified by:
      debug in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      message - a human-readable message to log.
      args - arguments to parameterize the message.
    • trace

      public void trace​(String correlationId, String message, Object... args)
      Logs a low-level debug information for troubleshooting.
      Specified by:
      trace in interface ILogger
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      message - a human-readable message to log.
      args - arguments to parameterize the message.