Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.3.0
-
None
-
james 2.3.0rc1
Description
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) {
{ continue; }
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")))try
Unknown macro: { 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) {}
{ return ste[i].getClassName().replace("$", "."); }
}
if (!found) return null;
trycatch (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 [apache.james@localhost]
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 [apache.james@localhost]
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