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/dac35137 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dac35137 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dac35137 Branch: refs/heads/master Commit: dac35137d0c8019ea00e789ef739c6738924bc08 Parents: 79e2f13 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Aug 5 13:19:07 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Aug 5 13:19:07 2015 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/LoggingLevel.java | 19 +++----- .../java/org/apache/camel/LoggingLevelTest.java | 47 ++++++++++++++++++++ .../file/remote/SftpConfiguration.java | 5 +-- .../component/file/remote/SftpOperations.java | 10 ++--- 4 files changed, 61 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/dac35137/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 434c9dd..b3c8e88 100644 --- a/camel-core/src/main/java/org/apache/camel/LoggingLevel.java +++ b/camel-core/src/main/java/org/apache/camel/LoggingLevel.java @@ -25,23 +25,18 @@ import javax.xml.bind.annotation.XmlEnum; */ @XmlEnum public enum LoggingLevel { - DEBUG, ERROR, INFO, TRACE, WARN, OFF; + + TRACE, DEBUG, INFO, WARN, ERROR, OFF; /** * Is the given logging level equal or higher than the current level. */ - public boolean isGE(LoggingLevel level) { - if (this == OFF) { + public boolean isEnabled(LoggingLevel level) { + // off is always false + if (this == OFF || level == 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; + + return this.compareTo(level) <= 0; } } http://git-wip-us.apache.org/repos/asf/camel/blob/dac35137/camel-core/src/test/java/org/apache/camel/LoggingLevelTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/LoggingLevelTest.java b/camel-core/src/test/java/org/apache/camel/LoggingLevelTest.java new file mode 100644 index 0000000..508d3bf --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/LoggingLevelTest.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel; + +import junit.framework.TestCase; +import org.junit.Test; + +public class LoggingLevelTest extends TestCase { + + @Test + public void testLoggingLevelInfo() throws Exception { + assertTrue(LoggingLevel.INFO.isEnabled(LoggingLevel.ERROR)); + assertTrue(LoggingLevel.INFO.isEnabled(LoggingLevel.WARN)); + assertTrue(LoggingLevel.INFO.isEnabled(LoggingLevel.INFO)); + + assertFalse(LoggingLevel.INFO.isEnabled(LoggingLevel.DEBUG)); + assertFalse(LoggingLevel.INFO.isEnabled(LoggingLevel.TRACE)); + + assertFalse(LoggingLevel.INFO.isEnabled(LoggingLevel.OFF)); + } + + @Test + public void testLoggingLevelWARN() throws Exception { + assertTrue(LoggingLevel.WARN.isEnabled(LoggingLevel.ERROR)); + assertTrue(LoggingLevel.WARN.isEnabled(LoggingLevel.WARN)); + + assertFalse(LoggingLevel.WARN.isEnabled(LoggingLevel.INFO)); + assertFalse(LoggingLevel.WARN.isEnabled(LoggingLevel.DEBUG)); + assertFalse(LoggingLevel.WARN.isEnabled(LoggingLevel.TRACE)); + + assertFalse(LoggingLevel.WARN.isEnabled(LoggingLevel.OFF)); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/dac35137/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 8d56d5d..9171b93 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 @@ -254,9 +254,8 @@ public class SftpConfiguration extends RemoteFileConfiguration { } /** - * Sets the logging level of JSCH activity. - * <p/> - * Because JSCH is verbose by default at INFO level, the default value is <tt>WARN</tt> + * The logging level to use for JSCH activity logging. + * As JSCH is verbose at by default at INFO level the threshold is WARN by default. */ public void setJschLoggingLevel(LoggingLevel jschLoggingLevel) { this.jschLoggingLevel = jschLoggingLevel; http://git-wip-us.apache.org/repos/asf/camel/blob/dac35137/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 752a678..f19f70b 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 @@ -343,15 +343,15 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry> switch (level) { case FATAL: // use ERROR as FATAL - return loggingLevel.isGE(LoggingLevel.ERROR) && LOG.isErrorEnabled(); + return loggingLevel.isEnabled(LoggingLevel.ERROR) && LOG.isErrorEnabled(); case ERROR: - return loggingLevel.isGE(LoggingLevel.ERROR) && LOG.isErrorEnabled(); + return loggingLevel.isEnabled(LoggingLevel.ERROR) && LOG.isErrorEnabled(); case WARN: - return loggingLevel.isGE(LoggingLevel.WARN) && LOG.isWarnEnabled(); + return loggingLevel.isEnabled(LoggingLevel.WARN) && LOG.isWarnEnabled(); case INFO: - return loggingLevel.isGE(LoggingLevel.INFO) && LOG.isInfoEnabled(); + return loggingLevel.isEnabled(LoggingLevel.INFO) && LOG.isInfoEnabled(); default: - return loggingLevel.isGE(LoggingLevel.DEBUG) && LOG.isDebugEnabled(); + return loggingLevel.isEnabled(LoggingLevel.DEBUG) && LOG.isDebugEnabled(); } }