Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1192

Dynamic Subject for SMTP Appender

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.4.1, 2.15.0
    • 2.6, 2.15.0
    • Appenders
    • ALL

    Description

      It is annoying to have log messages sent to users via SMTP Appender with a static subject, requiring recipients to open each of possibly a vast amount of log emails in order to find out what went wrong.

      Users should be able to insert runtime diagnostic context information to the message text AND to the message subject as well.

      While the first seems to be working with Patternlayout using the mechanism with the %X

      {<key>}

      pattern based on a NDC or MDC <key> in the "ConversionPattern" parameter, it does NOT work with the "Subject" parameter with log4j (neither 1.2 nor 2.x), though some bloggers suggest it, e.g. http://stackoverflow.com/a/7015453.

      See http://stackoverflow.com/questions/29435825/log4j2-custom-email-subject-from-map as an example where others found this also.

      This issue should have been fixed long ago.

      I suggest to extend SMTP appender in order to be able to use %X and other Pattern conversion in the "Subject" parameter properly.

      http://openutils.sourceforge.net/openutils-log4j/smtpappender.html
      has already done the part for applying PatternLayout to the SMTP Appender "Subject". I didn't test if this works properly.
      Maybe this work can be included into log4j with minimal effort?

      This feature has originally been realized in LOGBACK using an MDC in Patternlayouts: http://logback.qos.ch/manual/mdc.html

      Attachments

        1. MaxLengthConverter.java
          4 kB
          Thies Wellpott
        2. ExtendedSmtpManager.java
          31 kB
          Thies Wellpott
        3. ExtendedSmtpAppender.java
          9 kB
          Thies Wellpott

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              jbsfsax Jörg Bretschneider
              Votes:
              6 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h