Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C15F918693 for ; Wed, 5 Aug 2015 11:32:40 +0000 (UTC) Received: (qmail 38839 invoked by uid 500); 5 Aug 2015 11:32:40 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 38699 invoked by uid 500); 5 Aug 2015 11:32:40 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 38589 invoked by uid 99); 5 Aug 2015 11:32:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Aug 2015 11:32:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 74E10DFE61; Wed, 5 Aug 2015 11:32:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Wed, 05 Aug 2015 11:32:42 -0000 Message-Id: In-Reply-To: <0b73a683a2bf4a1db3dd27ce35e22d1a@git.apache.org> References: <0b73a683a2bf4a1db3dd27ce35e22d1a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/4] camel git commit: CAMEL-9054: sftp - Reduce logging noise from JSCH CAMEL-9054: sftp - Reduce logging noise from JSCH Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d9856bd2 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d9856bd2 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d9856bd2 Branch: refs/heads/camel-2.15.x Commit: d9856bd2ada938d101ccb49f46d4e32292b05677 Parents: 9611cc4 Author: Claus Ibsen Authored: Wed Aug 5 13:00:56 2015 +0200 Committer: Claus Ibsen Committed: Wed Aug 5 13:39:51 2015 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/LoggingLevel.java | 20 +++++++++++++- .../file/remote/SftpConfiguration.java | 16 +++++++++++ .../component/file/remote/SftpOperations.java | 29 ++++++++++++-------- 3 files changed, 53 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d9856bd2/camel-core/src/main/java/org/apache/camel/LoggingLevel.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/LoggingLevel.java b/camel-core/src/main/java/org/apache/camel/LoggingLevel.java index a8958bf..434c9dd 100644 --- a/camel-core/src/main/java/org/apache/camel/LoggingLevel.java +++ b/camel-core/src/main/java/org/apache/camel/LoggingLevel.java @@ -25,5 +25,23 @@ import javax.xml.bind.annotation.XmlEnum; */ @XmlEnum public enum LoggingLevel { - DEBUG, ERROR, INFO, TRACE, WARN, OFF + DEBUG, ERROR, INFO, TRACE, WARN, OFF; + + /** + * Is the given logging level equal or higher than the current level. + */ + public boolean isGE(LoggingLevel level) { + if (this == OFF) { + return false; + } else if (level == WARN) { + return this == WARN || this == ERROR; + } else if (level == INFO) { + return this == INFO || this == WARN || this == ERROR; + } else if (level == DEBUG) { + return this == DEBUG || this == INFO || this == WARN || this == ERROR; + } else if (level == TRACE) { + return this != OFF; + } + return false; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/d9856bd2/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java index f7b21e8..855d84a 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java @@ -19,6 +19,7 @@ package org.apache.camel.component.file.remote; import java.net.URI; import java.security.KeyPair; +import org.apache.camel.LoggingLevel; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; @@ -59,6 +60,8 @@ public class SftpConfiguration extends RemoteFileConfiguration { private int compression; @UriParam private String preferredAuthentications; + @UriParam(defaultValue = "WARN") + private LoggingLevel jschLoggingLevel = LoggingLevel.WARN; public SftpConfiguration() { setProtocol("sftp"); @@ -202,4 +205,17 @@ public class SftpConfiguration extends RemoteFileConfiguration { public String getPreferredAuthentications() { return preferredAuthentications; } + + public LoggingLevel getJschLoggingLevel() { + return jschLoggingLevel; + } + + /** + * Sets the logging level of JSCH activity. + *

+ * Because JSCH is verbose by default at INFO level, the default value is WARN + */ + public void setJschLoggingLevel(LoggingLevel jschLoggingLevel) { + this.jschLoggingLevel = jschLoggingLevel; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/d9856bd2/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java index 9790ef9..e6e7fd9 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java @@ -46,6 +46,7 @@ import com.jcraft.jsch.UserInfo; import org.apache.camel.Exchange; import org.apache.camel.InvalidPayloadException; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.FileComponent; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileEndpoint; @@ -165,7 +166,7 @@ public class SftpOperations implements RemoteFileOperations protected Session createSession(final RemoteFileConfiguration configuration) throws JSchException { final JSch jsch = new JSch(); - JSch.setLogger(new JSchLogger()); + JSch.setLogger(new JSchLogger(endpoint.getConfiguration().getJschLoggingLevel())); SftpConfiguration sftpConfig = (SftpConfiguration) configuration; @@ -334,19 +335,25 @@ public class SftpOperations implements RemoteFileOperations private static final class JSchLogger implements com.jcraft.jsch.Logger { + private final LoggingLevel loggingLevel; + + private JSchLogger(LoggingLevel loggingLevel) { + this.loggingLevel = loggingLevel; + } + public boolean isEnabled(int level) { switch (level) { case FATAL: // use ERROR as FATAL - return LOG.isErrorEnabled(); + return loggingLevel.isGE(LoggingLevel.ERROR) && LOG.isErrorEnabled(); case ERROR: - return LOG.isErrorEnabled(); + return loggingLevel.isGE(LoggingLevel.ERROR) && LOG.isErrorEnabled(); case WARN: - return LOG.isWarnEnabled(); + return loggingLevel.isGE(LoggingLevel.WARN) && LOG.isWarnEnabled(); case INFO: - return LOG.isInfoEnabled(); + return loggingLevel.isGE(LoggingLevel.INFO) && LOG.isInfoEnabled(); default: - return LOG.isDebugEnabled(); + return loggingLevel.isGE(LoggingLevel.DEBUG) && LOG.isDebugEnabled(); } } @@ -354,19 +361,19 @@ public class SftpOperations implements RemoteFileOperations switch (level) { case FATAL: // use ERROR as FATAL - LOG.error("JSCH -> " + message); + LOG.error("JSCH -> {}", message); break; case ERROR: - LOG.error("JSCH -> " + message); + LOG.error("JSCH -> {}", message); break; case WARN: - LOG.warn("JSCH -> " + message); + LOG.warn("JSCH -> {}", message); break; case INFO: - LOG.info("JSCH -> " + message); + LOG.info("JSCH -> {}", message); break; default: - LOG.debug("JSCH -> " + message); + LOG.debug("JSCH -> {}", message); break; } }