INT-1655 added support for JSch Loging for SFTP adapter, updated documentation

This commit is contained in:
Oleg Zhurakousky
2010-12-01 16:06:00 -05:00
parent 41d64cdf6b
commit ee5b305260
4 changed files with 62 additions and 3 deletions

View File

@@ -157,4 +157,22 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
value that computes the <emphasis>file name</emphasis> based on its original name while also appending a suffix: '-foo'.
</para>
</section>
<section id="sftp-jsch-logging">
<title>SFTP/JSCH Logging</title>
<para>
Since we use JSch libraries (http://www.jcraft.com/jsch/) to provide SFTP support some times you may require
more information from the JSch API itself especially if something is not working properly
(e.g., Authentication exceptions etc.). Unfortunately JSch does not use commonly used logging facilities and instead
relies on the custom implementation of <classname>com.jcraft.jsch.Logger</classname> interface.
Since Spring Integration 2.0.1 we've implemented this interface, so now all you need to do to enable
JSch logging is to configure your logger the way you usually do. For example below is sample configuration of a
logger using Log4J.
<programlisting language="java"><![CDATA[log4j.category.com.jcraft.jsch=DEBUG]]></programlisting>
</para>
</section>
</chapter>

View File

@@ -30,10 +30,11 @@ import com.jcraft.jsch.UserInfo;
*
* @author Josh Long
* @author Mario Gray
* @author Oleg Zhurakousky
* @since 2.0
*/
public class DefaultSftpSessionFactory implements SessionFactory {
private volatile String host;
private volatile int port = 22; // the default
@@ -97,6 +98,8 @@ public class DefaultSftpSessionFactory implements SessionFactory {
}
private com.jcraft.jsch.Session initJschSession() throws Exception {
JSch.setLogger(new JschLogger());
if (this.port <= 0) {
this.port = 22;
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.sftp.session;
import org.apache.log4j.Level;
import com.jcraft.jsch.Logger;
/**
* @author Oleg Zhurakousky
* @since 2.0.1
*/
class JschLogger implements Logger {
private final static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("com.jcraft.jsch");
public boolean isEnabled(int level) {
return true;
}
public void log(int level, String message) {
logger.log(Level.toLevel(level), message);
}
}

View File

@@ -4,5 +4,6 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
log4j.category.org.springframework=WARN
log4j.category.org.springframework.integration=DEBUG
log4j.category.com.jcraft.jsch=DEBUG
log4j.category.org.springframework.integration=WARN
log4j.category.org.springframework.integration.sftp=DEBUG