Class JSchSlf4jLogger

java.lang.Object
org.kiwiproject.jsch.JSchSlf4jLogger
All Implemented Interfaces:
com.jcraft.jsch.Logger

public class JSchSlf4jLogger extends Object implements com.jcraft.jsch.Logger
Custom logger implementing Jsch's Logger class.

Some implementation notes:

  • JSch's INFO level logging is very verbose, so we are treating it like DEBUG level
  • Jsch has both ERROR and FATAL levels, but SLF4J only has ERROR, so we treat both as ERROR in SLF4J
  • Field Summary

    Fields inherited from interface com.jcraft.jsch.Logger

    DEBUG, ERROR, FATAL, INFO, WARN
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct an instance with a default logger, e.g. for org.kiwiproject.jsch.JSchSlf4jLogger.
    JSchSlf4jLogger(org.slf4j.Logger slf4jLogger)
    Construct an instance using the given SLF4J logger.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isEnabled(int level)
    Is the given level enabled?
    void
    log(int level, String message)
    Log the given message at the given level.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JSchSlf4jLogger

      public JSchSlf4jLogger()
      Construct an instance with a default logger, e.g. for org.kiwiproject.jsch.JSchSlf4jLogger.

      Usually you should use JSchSlf4jLogger(Logger) in order to specify the SLF4J Logger explicitly to control the logging level and logger name.

    • JSchSlf4jLogger

      public JSchSlf4jLogger(org.slf4j.Logger slf4jLogger)
      Construct an instance using the given SLF4J logger.
      Parameters:
      slf4jLogger - the SLF4J Logger that will be the destination for JSch logging output.
  • Method Details

    • isEnabled

      public boolean isEnabled(int level)
      Is the given level enabled?
      Specified by:
      isEnabled in interface com.jcraft.jsch.Logger
      Parameters:
      level - one of the public constants in Logger
      Returns:
      true if the level is enabled in the underlying SLF4J logger.
    • log

      public void log(int level, String message)
      Log the given message at the given level.

      If provided an invalid level, a message will be logged about the invalid level, along with the given message, at the SLF4J ERROR level. This is intended to provide both information about the problem and provide the original message, rather than throwing an exception or suppressing the message.

      Specified by:
      log in interface com.jcraft.jsch.Logger
      Parameters:
      level - one of the public constants in Logger
      message - the message to log