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 ba...@apache.org on 2006/09/25 20:27:00 UTC

svn commit: r449767 - in /james/server/trunk/src: conf/ java/org/apache/james/transport/ java/org/apache/mailet/

Author: bago
Date: Mon Sep 25 11:26:59 2006
New Revision: 449767

URL: http://svn.apache.org/viewvc?view=rev&rev=449767
Log:
Each mailet/matcher is now given a child logger and does not need anymore to prepend its own name in each log call (JAMES-601).
This way we have much more control on the log granularity. This is also a good step towards having a more fine grained logging capability published to mailets.

Modified:
    james/server/trunk/src/conf/james-server.xml
    james/server/trunk/src/java/org/apache/james/transport/JamesMailetLoader.java
    james/server/trunk/src/java/org/apache/james/transport/JamesMatcherLoader.java
    james/server/trunk/src/java/org/apache/james/transport/Loader.java
    james/server/trunk/src/java/org/apache/mailet/GenericMailet.java
    james/server/trunk/src/java/org/apache/mailet/GenericMatcher.java

Modified: james/server/trunk/src/conf/james-server.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-server.xml?view=diff&rev=449767&r1=449766&r2=449767
==============================================================================
--- james/server/trunk/src/conf/james-server.xml (original)
+++ james/server/trunk/src/conf/james-server.xml Mon Sep 25 11:26:59 2006
@@ -29,6 +29,12 @@
       <category name="" log-level="INFO">
         <log-target id-ref="default"/>
       </category>
+      <category name="mailetpackages" log-level="INFO">
+        <log-target id-ref="James-Mailet-target"/>
+      </category>
+      <category name="matcherpackages" log-level="INFO">
+        <log-target id-ref="James-Mailet-target"/>
+      </category>
       <category name="James.Mailet" log-level="INFO">
         <log-target id-ref="James-Mailet-target"/>
       </category>

Modified: james/server/trunk/src/java/org/apache/james/transport/JamesMailetLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/JamesMailetLoader.java?view=diff&rev=449767&r1=449766&r2=449767
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/JamesMailetLoader.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/JamesMailetLoader.java Mon Sep 25 11:26:59 2006
@@ -48,11 +48,11 @@
             for (int i = 0; i < packages.size(); i++) {
                 String className = (String) packages.elementAt(i) + mailetName;
                 try {
+                    Mailet mailet = (Mailet) Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
                     MailetConfigImpl configImpl = new MailetConfigImpl();
                     configImpl.setMailetName(mailetName);
                     configImpl.setConfiguration(configuration);
-                    configImpl.setMailetContext(mailetContext);
-                    Mailet mailet = (Mailet) Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+                    configImpl.setMailetContext(new MailetContextWrapper(mailetContext, getLogger().getChildLogger(mailetName))); 
                     mailet.init(configImpl);
                     return mailet;
                 } catch (ClassNotFoundException cnfe) {

Modified: james/server/trunk/src/java/org/apache/james/transport/JamesMatcherLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/JamesMatcherLoader.java?view=diff&rev=449767&r1=449766&r2=449767
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/JamesMatcherLoader.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/JamesMatcherLoader.java Mon Sep 25 11:26:59 2006
@@ -54,11 +54,11 @@
             for (i = 0; i < packages.size(); i++) {
                 String className = (String) packages.elementAt(i) + matchName;
                 try {
+                    Matcher matcher = (Matcher) Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
                     MatcherConfigImpl configImpl = new MatcherConfigImpl();
                     configImpl.setMatcherName(matchName);
                     configImpl.setCondition(condition);
-                    configImpl.setMailetContext(mailetContext);
-                    Matcher matcher = (Matcher) Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+                    configImpl.setMailetContext(new MailetContextWrapper(mailetContext, getLogger().getChildLogger(matchName)));
                     matcher.init(configImpl);
                     return matcher;
                 } catch (ClassNotFoundException cnfe) {

Modified: james/server/trunk/src/java/org/apache/james/transport/Loader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/Loader.java?view=diff&rev=449767&r1=449766&r2=449767
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/Loader.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/Loader.java Mon Sep 25 11:26:59 2006
@@ -20,6 +20,8 @@
 
 package org.apache.james.transport;
 import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.Vector;
 
 import org.apache.avalon.framework.activity.Initializable;
@@ -30,12 +32,18 @@
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.DefaultServiceManager;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
 import org.apache.mailet.MailetContext;
 
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
 /**
  *
  * $Id$
@@ -118,5 +126,182 @@
      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
      */
     public abstract void configure(Configuration arg0) throws ConfigurationException;
+
+    /**
+     * Wrapper fot a MailetContext that simply override the used logger.
+     */
+    protected final static class MailetContextWrapper implements MailetContext {
+        
+        /** the mailetContext */
+        private MailetContext mailetContext;
+        /** the logger */
+        private Logger logger;
+
+        /**
+         * Create a mailetContext wrapper that use a different logger for the log
+         * operations
+         * 
+         * @param mailetContext the mailet context to be wrapped
+         * @param logger the logger to be used instead of the parent one. 
+         */
+        public MailetContextWrapper(MailetContext mailetContext, Logger logger) {
+            this.mailetContext = mailetContext;
+            this.logger = logger;
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#bounce(org.apache.mailet.Mail, java.lang.String)
+         */
+        public void bounce(Mail mail, String message) throws MessagingException {
+            mailetContext.bounce(mail, message);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#bounce(org.apache.mailet.Mail, java.lang.String, org.apache.mailet.MailAddress)
+         */
+        public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
+            mailetContext.bounce(mail, message, bouncer);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getAttribute(java.lang.String)
+         */
+        public Object getAttribute(String name) {
+            return mailetContext.getAttribute(name);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getAttributeNames()
+         */
+        public Iterator getAttributeNames() {
+            return mailetContext.getAttributeNames();
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getMailServers(java.lang.String)
+         */
+        public Collection getMailServers(String host) {
+            return mailetContext.getMailServers(host);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getMajorVersion()
+         */
+        public int getMajorVersion() {
+            return mailetContext.getMajorVersion();
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getMinorVersion()
+         */
+        public int getMinorVersion() {
+            return mailetContext.getMinorVersion();
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getPostmaster()
+         */
+        public MailAddress getPostmaster() {
+            return mailetContext.getPostmaster();
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getSMTPHostAddresses(java.lang.String)
+         */
+        public Iterator getSMTPHostAddresses(String domainName) {
+            return mailetContext.getSMTPHostAddresses(domainName);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#getServerInfo()
+         */
+        public String getServerInfo() {
+            return mailetContext.getServerInfo();
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#isLocalEmail(org.apache.mailet.MailAddress)
+         */
+        public boolean isLocalEmail(MailAddress mailAddress) {
+            return mailetContext.isLocalEmail(mailAddress);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#isLocalServer(java.lang.String)
+         */
+        public boolean isLocalServer(String serverName) {
+            return mailetContext.isLocalServer(serverName);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#isLocalUser(java.lang.String)
+         */
+        public boolean isLocalUser(String userAccount) {
+            return mailetContext.isLocalUser(userAccount);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#log(java.lang.String)
+         */
+        public void log(String message) {
+            logger.info(message);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#log(java.lang.String, java.lang.Throwable)
+         */
+        public void log(String message, Throwable t) {
+            logger.info(message, t);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#removeAttribute(java.lang.String)
+         */
+        public void removeAttribute(String name) {
+            mailetContext.removeAttribute(name);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#sendMail(javax.mail.internet.MimeMessage)
+         */
+        public void sendMail(MimeMessage msg) throws MessagingException {
+            mailetContext.sendMail(msg);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#sendMail(org.apache.mailet.MailAddress, java.util.Collection, javax.mail.internet.MimeMessage)
+         */
+        public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException {
+            mailetContext.sendMail(sender, recipients, msg);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#sendMail(org.apache.mailet.MailAddress, java.util.Collection, javax.mail.internet.MimeMessage, java.lang.String)
+         */
+        public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg, String state) throws MessagingException {
+            mailetContext.sendMail(sender, recipients, msg, state);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#sendMail(org.apache.mailet.Mail)
+         */
+        public void sendMail(Mail mail) throws MessagingException {
+            mailetContext.sendMail(mail);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#setAttribute(java.lang.String, java.lang.Object)
+         */
+        public void setAttribute(String name, Object object) {
+            mailetContext.setAttribute(name, object);
+        }
+
+        /**
+         * @see org.apache.mailet.MailetContext#storeMail(org.apache.mailet.MailAddress, org.apache.mailet.MailAddress, javax.mail.internet.MimeMessage)
+         */
+        public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException {
+            mailetContext.storeMail(sender, recipient, msg);
+        }
+    }
 
 }

Modified: james/server/trunk/src/java/org/apache/mailet/GenericMailet.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/mailet/GenericMailet.java?view=diff&rev=449767&r1=449766&r2=449767
==============================================================================
--- james/server/trunk/src/java/org/apache/mailet/GenericMailet.java (original)
+++ james/server/trunk/src/java/org/apache/mailet/GenericMailet.java Mon Sep 25 11:26:59 2006
@@ -173,34 +173,23 @@
     }
 
     /**
-     * Writes the specified message to a mailet log file, prepended by
-     * the mailet's name.
+     * Writes the specified message to a mailet log file.
      *
      * @param message - a String specifying the message to be written to the log file
      */
     public void log(String message) {
-        StringBuffer logBuffer =
-            new StringBuffer(256)
-                    .append(getMailetName())
-                    .append(": ")
-                    .append(message);
-        getMailetContext().log(logBuffer.toString());
+        getMailetContext().log(message);
     }
 
     /**
      * Writes an explanatory message and a stack trace for a given Throwable
-     * exception to the mailet log file, prepended by the mailet's name.
+     * exception to the mailet log file.
      *
      * @param message - a String that describes the error or exception
      * @param t - the java.lang.Throwable to be logged
      */
     public void log(String message, Throwable t) {
-        StringBuffer logBuffer =
-            new StringBuffer(256)
-                    .append(config.getMailetName())
-                    .append(": ")
-                    .append(message);
-        getMailetContext().log(logBuffer.toString(), t);
+        getMailetContext().log(message, t);
     }
 
     /**

Modified: james/server/trunk/src/java/org/apache/mailet/GenericMatcher.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/mailet/GenericMatcher.java?view=diff&rev=449767&r1=449766&r2=449767
==============================================================================
--- james/server/trunk/src/java/org/apache/mailet/GenericMatcher.java (original)
+++ james/server/trunk/src/java/org/apache/mailet/GenericMatcher.java Mon Sep 25 11:26:59 2006
@@ -132,34 +132,23 @@
     }
 
     /**
-     * Writes the specified message to a matcher log file, prepended by
-     * the matcher's name.
+     * Writes the specified message to a matcher log file.
      *
      * @param message - a String specifying the message to be written to the log file
      */
     public void log(String message) {
-        StringBuffer logBuffer = 
-            new StringBuffer(256)
-                    .append(getMatcherName())
-                    .append(": ")
-                    .append(message);
-        getMailetContext().log(logBuffer.toString());
+        getMailetContext().log(message);
     }
 
     /**
      * Writes an explanatory message and a stack trace for a given Throwable
-     * exception to the matcher log file, prepended by the matcher's name.
+     * exception to the matcher log file.
      *
      * @param message - a String that describes the error or exception
      * @param t - the java.lang.Throwable error or exception
      */
     public void log(String message, Throwable t) {
-        StringBuffer logBuffer = 
-            new StringBuffer(256)
-                    .append(getMatcherName())
-                    .append(": ")
-                    .append(message);
-        getMailetContext().log(logBuffer.toString(), t);
+        getMailetContext().log(message, t);
     }
 
     /**



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