Author: rdonkin Date: Tue Dec 23 11:46:37 2008 New Revision: 729076 URL: http://svn.apache.org/viewvc?rev=729076&view=rev Log: Added quiet parameter (for minimal logging). Added adapter to allow Sieve to log to the mailet log system.
Added: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/CommonsLoggingAdapter.java (with props) Modified: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java Added: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/CommonsLoggingAdapter.java URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/CommonsLoggingAdapter.java?rev=729076&view=auto ============================================================================== --- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/CommonsLoggingAdapter.java (added) +++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/CommonsLoggingAdapter.java Tue Dec 23 11:46:37 2008 @@ -0,0 +1,142 @@ +/**************************************************************** + * 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.jsieve.mailet; + +import org.apache.commons.logging.Log; +import org.apache.mailet.base.GenericMailet; + +/** + * Adapts commons logging to mailet logging. + */ +class CommonsLoggingAdapter implements Log { + + 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 GenericMailet mailet; + private final int level; + + public CommonsLoggingAdapter(final GenericMailet mailet, final int level) { + super(); + this.mailet = mailet; + this.level = level; + } + + public void debug(Object message) { + if (isDebugEnabled()) { + mailet.log(message == null ? "NULL" : message.toString()); + } + } + + public void debug(Object message, Throwable t) { + if (isDebugEnabled()) { + mailet.log(message == null ? "NULL" : message.toString(), t); + } + } + + public void error(Object message) { + if (isErrorEnabled()) { + mailet.log(message == null ? "NULL" : message.toString()); + } + } + + public void error(Object message, Throwable t) { + if (isErrorEnabled()) { + mailet.log(message == null ? "NULL" : message.toString(), t); + } + } + + public void fatal(Object message) { + if (isFatalEnabled()) { + mailet.log(message == null ? "NULL" : message.toString()); + } + } + + public void fatal(Object message, Throwable t) { + if (isFatalEnabled()) { + mailet.log(message == null ? "NULL" : message.toString(), t); + } + } + + public void info(Object message) { + if (isInfoEnabled()) { + mailet.log(message == null ? "NULL" : message.toString()); + } + } + + public void info(Object message, Throwable t) { + if (isInfoEnabled()) { + mailet.log(message == null ? "NULL" : message.toString(), 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()) { + mailet.log(message == null ? "NULL" : message.toString()); + } + } + + public void trace(Object message, Throwable t) { + if (isTraceEnabled()) { + mailet.log(message == null ? "NULL" : message.toString(), t); + } + } + + public void warn(Object message) { + if (isWarnEnabled()) { + mailet.log(message == null ? "NULL" : message.toString()); + } + } + + public void warn(Object message, Throwable t) { + if (isWarnEnabled()) { + mailet.log(message == null ? "NULL" : message.toString(), t); + } + } + + +} Propchange: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/CommonsLoggingAdapter.java ------------------------------------------------------------------------------ svn:mergeinfo = Modified: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java?rev=729076&r1=729075&r2=729076&view=diff ============================================================================== --- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java (original) +++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java Tue Dec 23 11:46:37 2008 @@ -73,6 +73,8 @@ private boolean verbose = false; private boolean consume = true; + /** Indicates whether this mailet should log minimal information */ + private boolean quiet = true; private SieveFactory factory; @@ -146,6 +148,7 @@ /** * Sets whether logging should be verbose for this mailet. * This property is set by init parameters. + * This setting overrides {...@link #isQuiet()}. * @param verbose true when logging should be verbose, * false otherwise */ @@ -153,15 +156,49 @@ this.verbose = verbose; } + /** + * Is the logging for this mailet set to minimal? + * @return true + */ + public boolean isQuiet() { + return quiet; + } + /** + * Sets the logging for this mailet to minimal. + * This is overriden by {...@link #setVerbose(boolean)}. + * @param quiet true for minimal logging, false otherwise + */ + public void setQuiet(boolean quiet) { + this.quiet = quiet; + } + /** + * Is informational logging turned on? + * @return true when minimal logging is off, + * false when logging is minimal + */ + public boolean isInfoLoggingOn() { + return verbose || !quiet; + } + //@Override public void init(MailetConfig config) throws MessagingException { super.init(config); try { - factory = new ConfigurationManager().build(); + final ConfigurationManager configurationManager = new ConfigurationManager(); + final int logLevel; + if (verbose) { + logLevel = CommonsLoggingAdapter.TRACE; + } else if (quiet) { + logLevel = CommonsLoggingAdapter.FATAL; + } else { + logLevel = CommonsLoggingAdapter.WARN; + } + configurationManager.setLog(new CommonsLoggingAdapter(this, logLevel)); + factory = configurationManager.build(); } catch (SieveConfigurationException e) { throw new MessagingException("Failed to load standard Sieve configuration.", e); } @@ -231,7 +268,7 @@ } } } catch (Exception ex) { - getMailetContext().log("Error while storing mail.", ex); + log("Error while storing mail.", ex); errors.add(recipient); } } @@ -310,7 +347,9 @@ // seems very unfriendly. // So just log and store in INBOX. // - log("Cannot evaluate Sieve script. Storing mail in user INBOX.", ex); + if (isInfoLoggingOn()) { + log("Cannot evaluate Sieve script. Storing mail in user INBOX.", ex); + } storeMessageInbox(username, aMail); } } @@ -334,5 +373,6 @@ this.resetReturnPath = getInitParameter("resetReturnPath", true); this.consume = getInitParameter("consume", true); this.verbose = getInitParameter("verbose", false); + this.quiet = getInitParameter("quiet", false); } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org