You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/12/18 19:35:22 UTC

[46/50] [abbrv] james-project git commit: JAMES-2199 Use jcl-over-slf4j to replace a wrapper class

JAMES-2199 Use jcl-over-slf4j to replace a wrapper class

Log level, which could previously be set via Sieve mailet configuration (but was undocumented) will now rely on logging configuration.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d61009e3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d61009e3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d61009e3

Branch: refs/heads/master
Commit: d61009e3bb8a3a1d6fbf6aee0c47f5f7b0b24b7f
Parents: 5b7babc
Author: benwa <bt...@linagora.com>
Authored: Mon Dec 11 11:11:53 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Dec 18 20:31:55 2017 +0100

----------------------------------------------------------------------
 .../apache/james/transport/mailets/Sieve.java   |  10 +-
 .../mailets/jsieve/CommonsLoggingAdapter.java   | 188 --------------
 .../jsieve/CommonsLoggingAdapterTest.java       | 259 -------------------
 3 files changed, 3 insertions(+), 454 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d61009e3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Sieve.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Sieve.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Sieve.java
index 2822e80..55352a9 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Sieve.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Sieve.java
@@ -23,15 +23,15 @@ import javax.inject.Inject;
 import javax.mail.MessagingException;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.core.MailAddress;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.sieverepository.api.SieveRepository;
-import org.apache.james.transport.mailets.jsieve.CommonsLoggingAdapter;
 import org.apache.james.transport.mailets.jsieve.ResourceLocator;
 import org.apache.james.transport.mailets.jsieve.delivery.SieveExecutor;
 import org.apache.james.transport.mailets.jsieve.delivery.SievePoster;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.mailet.Mail;
-import org.apache.james.core.MailAddress;
 import org.apache.mailet.base.GenericMailet;
 
 /**
@@ -60,11 +60,7 @@ public class Sieve extends GenericMailet {
 
     @Override
     public void init() throws MessagingException {
-        Log log = CommonsLoggingAdapter.builder()
-            .wrappedLogger(getMailetContext().getLogger())
-            .quiet(getInitParameter("quiet", false))
-            .verbose(getInitParameter("verbose", false))
-            .build();
+        Log log = LogFactory.getLog(Sieve.class);
         sieveExecutor = SieveExecutor.builder()
             .resourceLocator(resourceLocator)
             .mailetContext(getMailetContext())

http://git-wip-us.apache.org/repos/asf/james-project/blob/d61009e3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapter.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapter.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapter.java
deleted file mode 100644
index bc80e40..0000000
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapter.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/****************************************************************
- * 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.james.transport.mailets.jsieve;
-
-import java.util.Optional;
-
-import org.apache.commons.logging.Log;
-import org.slf4j.Logger;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Adapts commons logging to mailet logging.
- */
-public class CommonsLoggingAdapter implements Log {
-
-    public static Builder builder() {
-        return new Builder();
-    }
-
-    public static class Builder {
-        private Optional<Boolean> verbose = Optional.empty();
-        private Optional<Boolean> quiet = Optional.empty();
-        private Logger logger;
-
-        public Builder wrappedLogger(Logger logger) {
-            this.logger = logger;
-            return this;
-        }
-
-        public Builder verbose(boolean verbose) {
-            this.verbose = Optional.of(verbose);
-            return this;
-        }
-
-        public Builder quiet(boolean quiet) {
-            this.quiet = Optional.of(quiet);
-            return this;
-        }
-
-        public CommonsLoggingAdapter build() {
-            Preconditions.checkNotNull(logger);
-            Boolean quietParameter = quiet.orElse(false);
-            Boolean verboseParameter = verbose.orElse(false);
-            Preconditions.checkState(!(verboseParameter && quietParameter), "You can not specify a logger both verbose and quiet");
-            return new CommonsLoggingAdapter(logger, computeLogLevel(quietParameter, verboseParameter));
-        }
-
-        private int computeLogLevel(boolean quiet, boolean verbose) {
-            if (verbose) {
-                return CommonsLoggingAdapter.TRACE;
-            } else if (quiet) {
-                return CommonsLoggingAdapter.FATAL;
-            } else {
-                return CommonsLoggingAdapter.WARN;
-            }
-        }
-    }
-
-    public static final int TRACE = 6;
-    public static final int DEBUG = 5;
-    public static final int INFO = 4;
-    public static final int WARN = 3;
-    public static final int ERROR = 2;
-    public static final int FATAL = 1;
-    
-    private final Logger logger;
-    private final int level;
-    
-    private CommonsLoggingAdapter(Logger logger, final int level) {
-        super();
-        this.logger = logger;
-        this.level = level;
-    }
-
-    public void debug(Object message) {
-        if (isDebugEnabled()) {
-            logger.debug("{}", (message == null ? "NULL" : message));
-        }
-    }
-
-    public void debug(Object message, Throwable t) {
-        if (isDebugEnabled()) {
-            logger.debug("{}", (message == null ? "NULL" : message), t);
-        } 
-    }
-
-    public void error(Object message) {
-        if (isErrorEnabled()) {
-            logger.error("{}", (message == null ? "NULL" : message));
-        }
-    }
-
-    public void error(Object message, Throwable t) {
-        if (isErrorEnabled()) {
-            logger.error("{}", (message == null ? "NULL" : message), t);
-        }
-    }
-
-    public void fatal(Object message) {
-        if (isFatalEnabled()) {
-            logger.error("{}", (message == null ? "NULL" : message));
-        }
-    }
-
-    public void fatal(Object message, Throwable t) {
-        if (isFatalEnabled()) {
-            logger.error("{}", (message == null ? "NULL" : message), t);
-        }
-    }
-
-    public void info(Object message) {
-        if (isInfoEnabled()) {
-            logger.info("{}", (message == null ? "NULL" : message));
-        }
-    }
-
-    public void info(Object message, Throwable t) {
-        if (isInfoEnabled()) {
-            logger.info("{}", (message == null ? "NULL" : message), t);
-        }
-    }
-
-    public boolean isDebugEnabled() {
-        return level >= DEBUG;
-    }
-
-    public boolean isErrorEnabled() {
-        return level >= ERROR;
-    }
-
-    public boolean isFatalEnabled() {
-        return level >= FATAL;
-    }
-
-    public boolean isInfoEnabled() {
-        return level >= INFO;
-    }
-
-    public boolean isTraceEnabled() {
-        return level >= TRACE;
-    }
-
-    public boolean isWarnEnabled() {
-        return level >= WARN;
-    }
-
-    public void trace(Object message) {
-        if (isTraceEnabled()) {
-            logger.trace("{}", (message == null ? "NULL" : message));
-        }
-    }
-
-    public void trace(Object message, Throwable t) {
-        if (isTraceEnabled()) {
-            logger.trace("{}", (message == null ? "NULL" : message), t);
-        }
-    }
-
-    public void warn(Object message) {
-        if (isWarnEnabled()) {
-            logger.warn("{}", (message == null ? "NULL" : message));
-        }
-    }
-
-    public void warn(Object message, Throwable t) {
-        if (isWarnEnabled()) {
-            logger.warn("{}", (message == null ? "NULL" : message), t);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d61009e3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapterTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapterTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapterTest.java
deleted file mode 100644
index 2fc9042..0000000
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/CommonsLoggingAdapterTest.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- *   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.james.transport.mailets.jsieve;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.slf4j.Logger;
-
-public class CommonsLoggingAdapterTest {
-
-    @Rule public ExpectedException expectedException = ExpectedException.none();
-    private Logger logger;
-
-    @Before
-    public void setUp() {
-        logger = mock(Logger.class);
-    }
-
-    @Test
-    public void buildShouldThrowWhenNoMailetSpecified() {
-        expectedException.expect(NullPointerException.class);
-
-        CommonsLoggingAdapter.builder().build();
-    }
-
-    @Test
-    public void buildShouldDefaultToLogLevelWarn() {
-        CommonsLoggingAdapter loggingAdapter = CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build();
-
-        assertThat(loggingAdapter.isTraceEnabled()).isFalse();
-        assertThat(loggingAdapter.isDebugEnabled()).isFalse();
-        assertThat(loggingAdapter.isInfoEnabled()).isFalse();
-        assertThat(loggingAdapter.isWarnEnabled()).isTrue();
-        assertThat(loggingAdapter.isErrorEnabled()).isTrue();
-        assertThat(loggingAdapter.isFatalEnabled()).isTrue();
-    }
-
-
-    @Test
-    public void buildShouldUseFatalWithQuiet() {
-        CommonsLoggingAdapter loggingAdapter = CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .quiet(true)
-            .build();
-
-        assertThat(loggingAdapter.isTraceEnabled()).isFalse();
-        assertThat(loggingAdapter.isDebugEnabled()).isFalse();
-        assertThat(loggingAdapter.isInfoEnabled()).isFalse();
-        assertThat(loggingAdapter.isWarnEnabled()).isFalse();
-        assertThat(loggingAdapter.isErrorEnabled()).isFalse();
-        assertThat(loggingAdapter.isFatalEnabled()).isTrue();
-    }
-
-    @Test
-    public void buildShouldUseTraceWithVerbose() {
-        CommonsLoggingAdapter loggingAdapter = CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .verbose(true)
-            .build();
-
-        assertThat(loggingAdapter.isTraceEnabled()).isTrue();
-        assertThat(loggingAdapter.isDebugEnabled()).isTrue();
-        assertThat(loggingAdapter.isInfoEnabled()).isTrue();
-        assertThat(loggingAdapter.isWarnEnabled()).isTrue();
-        assertThat(loggingAdapter.isErrorEnabled()).isTrue();
-        assertThat(loggingAdapter.isFatalEnabled()).isTrue();
-    }
-
-    @Test
-    public void buildShouldThrowWhenBothQuietAndVerbose() {
-        expectedException.expect(IllegalStateException.class);
-
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .verbose(true)
-            .quiet(true)
-            .build();
-    }
-
-    @Test
-    public void simpleLoggingInVerboseModeShouldWorkInDebug() {
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .verbose(true)
-            .build()
-            .debug(message);
-
-        verify(logger).debug(message);
-    }
-
-    @Test
-    public void exceptionLoggingInVerboseModeShouldWorkInDebug() {
-        Exception exception = new Exception();
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .verbose(true)
-            .build()
-            .debug(message, exception);
-
-        verify(logger).debug(message, exception);
-    }
-
-    @Test
-    public void simpleLoggingInInfoModeShouldNotWorkByDefault() {
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build()
-            .info(message);
-
-        verifyNoMoreInteractions(logger);
-    }
-
-    @Test
-    public void exceptionLoggingInInfoModeShouldNotWorkByDefault() {
-        Exception exception = new Exception();
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build()
-            .info(message, exception);
-
-        verifyNoMoreInteractions(logger);
-    }
-
-    @Test
-    public void simpleLoggingInWarnModeShouldWorkByDefault() {
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build()
-            .warn(message);
-
-        verify(logger).warn(message);
-    }
-
-    @Test
-    public void exceptionLoggingInWarnModeShouldWorkByDefault() {
-        Exception exception = new Exception();
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build()
-            .warn(message, exception);
-
-        verify(logger).warn(message, exception);
-    }
-
-    @Test
-    public void simpleLoggingInErrorModeShouldNotWorkWithQuiet() {
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .quiet(true)
-            .build()
-            .error(message);
-
-        verifyNoMoreInteractions(logger);
-    }
-
-    @Test
-    public void exceptionLoggingInErrorModeShouldNotWorkWithQuiet() {
-        Exception exception = new Exception();
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .quiet(true)
-            .build()
-            .error(message, exception);
-
-        verifyNoMoreInteractions(logger);
-    }
-
-    @Test
-    public void simpleLoggingInFatalModeShouldWorkWithQuiet() {
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .quiet(true)
-            .build()
-            .fatal(message);
-
-        verify(logger).error(message);
-    }
-
-    @Test
-    public void exceptionLoggingInFatalModeShouldWorkWithQuiet() {
-        Exception exception = new Exception();
-        String message = "Message";
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .quiet(true)
-            .build()
-            .fatal(message, exception);
-
-        verify(logger).error(message, exception);
-    }
-
-    @Test
-    public void logShouldHandleNullValue() {
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build()
-            .fatal(null);
-
-        verify(logger).error("NULL");
-    }
-
-    @Test
-    public void logShouldHandleNullValueWithException() {
-        Exception exception = new Exception();
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build()
-            .fatal(null, exception);
-
-        verify(logger).error("NULL", exception);
-    }
-
-
-    @Test
-    public void logShouldHandleNullException() {
-        CommonsLoggingAdapter.builder()
-            .wrappedLogger(logger)
-            .build()
-            .fatal(null, null);
-
-        verify(logger).error("NULL", (Throwable) null);
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org