[ http://issues.apache.org/jira/browse/JAMES-601?page=all ]

Stefano Bagnara updated JAMES-601:
----------------------------------

    Attachment: JAMES-601.diff

Example on creating a child logger for each mailet.. UNTESTED!

> Add Class detail in logs of James.Mailet (patch)
> ------------------------------------------------
>
>                 Key: JAMES-601
>                 URL: http://issues.apache.org/jira/browse/JAMES-601
>             Project: James
>          Issue Type: Improvement
>          Components: Mailet API, James Core, Matchers/Mailets (bundled), 
> Remote Delivery, Mailet Contributions
>    Affects Versions: 2.3.0rc1
>         Environment: james 2.3.0rc1
>            Reporter: Guillermo Grandes
>         Attachments: JAMES-601.diff, James-final-20060923.diff, 
> James.java.diff, James.java.diff, JamesChildsLogger.java.diff
>
>
> In order to improve the organization and operation of logs I have thought 
> about this piece of code, without change Mailet API and that does not force 
> to make great changes in the Mailets.
> This code affects :
> http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/James.java
> ==============================================
> /**
> * Return the logger for the Mailet API
> *
> * @return the logger for the Mailet API
> */
> private Logger getMailetLogger() {     // it replaces the original method
>     if (mailetLogger == null) {
>         mailetLogger = getLogger().getChildLogger("Mailet");
>     }
>     String p = findParentCaller();
>     return ((p == null) ? mailetLogger : mailetLogger.getChildLogger(p));
> }
> /**
> * Return the Caller Mailet
> *
> * @return the ClassName for the Caller Mailet / Matcher
> */
> private String findParentCaller() {    // it is a new method
>     try {
>         throw new Exception();
>     }
>     catch (Throwable t) {
>         StackTraceElement[] ste = t.getStackTrace();
>         int i;
>         boolean found = false;
>         for (i = 0; i < ste.length; i++) {
>             String cn = ste[i].getClassName();
>             if (cn.startsWith("sun") || cn.startsWith("java") || 
> cn.startsWith("$")) continue; // speed-up
>             if ((cn.equals("org.apache.mailet.GenericMailet")) ||
>                 (cn.equals("org.apache.mailet.GenericMatcher"))) {
>                 continue;
>             }
>             try {
>                 Class c = Class.forName(cn);
>                 if 
> ((org.apache.mailet.GenericMailet.class.isAssignableFrom(c)) ||
>                     
> (org.apache.mailet.GenericMatcher.class.isAssignableFrom(c))) {
>                     found = true; break;
>                 }
>             }
>             catch(Exception ign) {}
>         }
>         if (!found) return null;
>         try {
>             return ste[i].getClassName().replace("$", ".");
>         }
>         catch (Exception ign) {}
>         return null;
>     }
> }
> ==============================================
> The result of this patch is:
> Original Logs...
> INFO  [James.Mailet] ToRepository: Storing mail Mail1222222222222-0 in 
> file://var/mail/inbound/
> INFO  [James.Mailet] RemoteDelivery: Attempting delivery of 
> Mail1222222222222-0 to host 192.168.1.1 at 192.168.1.1 for addresses [EMAIL 
> PROTECTED]
> INFO  [James.Mailet] BayesianAnalysisFeeder: maxSize: 200000
> Improved Logs...
> INFO  [James.Mailet.org.apache.james.transport.mailets.ToRepository] 
> ToRepository: Storing mail Mail1222222222222-0 in file://var/mail/inbound/
> INFO  [James.Mailet.org.apache.james.transport.mailets.RemoteDelivery] 
> RemoteDelivery: Attempting delivery of Mail1222222222222-0 to host 
> 192.168.1.1 at 192.168.1.1 for addresses [EMAIL PROTECTED]
> INFO  
> [James.Mailet.org.apache.james.transport.mailets.BayesianAnalysisFeeder] 
> BayesianAnalysisFeeder: maxSize: 200000
> With this you can organize your logs by Mailet / Category in environment.xml 
> :-)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to