Uploaded image for project: 'James Server'
  1. James Server
  2. JAMES-601

Add Class detail in logs of James.Mailet (patch)

    XMLWordPrintableJSON

    Details

      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) {
        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

        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) {}
        }
        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 [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

        Attachments

        1. James.java.diff
          0.3 kB
          Guillermo Grandes
        2. James.java.diff
          2 kB
          Guillermo Grandes
        3. JAMES-601.diff
          6 kB
          Stefano Bagnara
        4. JAMES-601-Plus.diff
          7 kB
          Guillermo Grandes
        5. JamesChildsLogger.java.diff
          1 kB
          Guillermo Grandes
        6. James-final-20060923.diff
          2 kB
          Guillermo Grandes

          Activity

            People

            • Assignee:
              bago Stefano Bagnara
              Reporter:
              technobcn Guillermo Grandes
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: