Search code examples
log4jspring-integrationslf4jjsch

Limit the output of jsch in Spring integration


I am trying to limit the output of the com.jcraft.jsch package in my Spring Boot applicatoin. My application uses Spring Intgration and has a log4j.properties files defining the following log levels

# Root logger option
log4j.rootLogger=DEBUG
log4j.category.com.jcraft.jsch=ERROR
log4j.category.org.springframework.integration.file=ERROR

And still, I get a whole lot of INFO levelled messages from that package... I was expecting it to filter it out. I followed the short description at the bottom of this link

Anyone with an idea as of why I still get flooded with comm. detail from jsch?

2015-05-21 11:12:55.750  INFO 10684 --- [ask-scheduler-1] com.jcraft.jsch                          : aes256-cbc is not available.
2015-05-21 11:12:55.750  INFO 10684 --- [ask-scheduler-1] com.jcraft.jsch                          : aes192-cbc is not available.
2015-05-21 11:12:55.750  INFO 10684 --- [ask-scheduler-1] com.jcraft.jsch                          : CheckKexes: diffie-hellman-group14-sha1
2015-05-21 11:12:55.770  INFO 10684 --- [ask-scheduler-1] com.jcraft.jsch                          : SSH_MSG_KEXINIT sent
2015-05-21 11:12:55.770  INFO 10684 --- [ask-scheduler-1] com.jcraft.jsch                          : SSH_MSG_KEXINIT received

I use log4j.1.2.17 and slf4j and my log4j.properties is located under src.main.resources


Solution

  • Answering my onw question, I had to do the following:

    1. Exclude logback classic from my boot starter. Since it Spring Boot relies on Apache commons-logging and logback. In gradle it looks like so:

      compile("org.springframework.boot:spring-boot-starter-integration") { exclude module: "logback-classic" }

    2. Add a dependency to my Log lib of choice, log4j:

      compile("org.springframework.boot:spring-boot-starter-log4j")

    3. Create a log4j.properies file inside src/main/java/resources/ where I state that jsch log level shoud be set to warning. log4j.category.com.jcraft.jsch=WARN

      log4j.debug=true log4j.rootLogger=info, stdout, file log4j.category.com.jcraft.jsch=WARN log4j.category.org.springframework.integration.file=info

      log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

      log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=C:\log4j-application.log log4j.appender.file.MaxFileSize=5MB log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n