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

Allow for bufferSize=0 in SMTP appender

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.9.0
    • Component/s: Appenders
    • Labels:
      None

      Description

      From the doc:
      "The number of logging events delivered in this e-mail depend on the value of BufferSize option. The SMTPAppender keeps only the last BufferSize logging events in its cyclic buffer. This keeps memory requirements at a reasonable level while still delivering useful application context. All events in the buffer are included in the email. The buffer will contain the most recent events of level TRACE to WARN preceding the event that triggered the email."
      https://logging.apache.org/log4j/2.x/manual/appenders.html#SMTPAppender

      The bufferSize is the number of messages preceding the message that triggered the event. They might be completely unrelated. One may not want to include them in the email at all, so having a bufferSize of 0 makes sense.

      This is however disallowed in the code:

      Caused by: java.lang.IllegalArgumentException: The maxSize argument (0) is not a positive integer.
      at org.apache.logging.log4j.core.util.CyclicBuffer.<init>(CyclicBuffer.java:41)
      at org.apache.logging.log4j.core.net.SmtpManager.<init>(SmtpManager.java:70)
      at org.apache.logging.log4j.core.net.SmtpManager$SMTPManagerFactory.createManager(SmtpManager.java:338)
      at org.apache.logging.log4j.core.net.SmtpManager$SMTPManagerFactory.createManager(SmtpManager.java:299)
      at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:71)
      at org.apache.logging.log4j.core.net.SmtpManager.getSMTPManager(SmtpManager.java:124)
      at org.apache.logging.log4j.core.appender.SmtpAppender.createAppender(SmtpAppender.java:142)

      1. CyclicBuffer.patch
        2 kB
        Ben Ludkiewicz

        Activity

        Hide
        garydgregory Gary Gregory added a comment -

        Tangent: Now that we are on Java 7, is there a JRE class we can use?

        Show
        garydgregory Gary Gregory added a comment - Tangent: Now that we are on Java 7, is there a JRE class we can use?
        Hide
        ralph.goers@dslextreme.com Ralph Goers added a comment - - edited

        For what? Sending mail? From what I see JavaMail is part of EE but is a standalone jar for SE.

        Show
        ralph.goers@dslextreme.com Ralph Goers added a comment - - edited For what? Sending mail? From what I see JavaMail is part of EE but is a standalone jar for SE.
        Hide
        garydgregory Gary Gregory added a comment -

        Sorry, I was thinking about our CyclicBuffer.

        Show
        garydgregory Gary Gregory added a comment - Sorry, I was thinking about our CyclicBuffer.
        Hide
        slowstrider Vermeulen added a comment -

        I was surprised by this too. I don't see why 0 would not be an appropriate value for how many prior logs to show. Especially if you know how to get to the actual log file and you value your mailbox storage, this may be the best option.

        I have now set the buffer value to 1 and this still shows me an unrelated log message. I didn't have this behavior with log4j 1.

        Show
        slowstrider Vermeulen added a comment - I was surprised by this too. I don't see why 0 would not be an appropriate value for how many prior logs to show. Especially if you know how to get to the actual log file and you value your mailbox storage, this may be the best option. I have now set the buffer value to 1 and this still shows me an unrelated log message. I didn't have this behavior with log4j 1.
        Hide
        nox Sebastian Frömel added a comment -

        Yes I was surprised too, since we update to Log4j2.
        We use the SMTP-sender for error emails with:

        <Filters>
        <ThresholdFilter level="ERROR" onMatch="ACCEPT" />
        </Filters>

        But with Buffer 1 we get sometimes Log-Messages (INFO/WARN) up to 30 Minutes before the error. - Not related at all.
        And if you not look closely enough you think you found a strange error, which is just a warn before the error.

        Our e-mail-filter also have a hard time, since they sometimes match text in the message before the error and sort them into the incorrect folder on our system.

        Overall not as nice as it could be

        Show
        nox Sebastian Frömel added a comment - Yes I was surprised too, since we update to Log4j2. We use the SMTP-sender for error emails with: <Filters> <ThresholdFilter level="ERROR" onMatch="ACCEPT" /> </Filters> But with Buffer 1 we get sometimes Log-Messages (INFO/WARN) up to 30 Minutes before the error. - Not related at all. And if you not look closely enough you think you found a strange error, which is just a warn before the error. Our e-mail-filter also have a hard time, since they sometimes match text in the message before the error and sort them into the incorrect folder on our system. Overall not as nice as it could be
        Hide
        garydgregory Gary Gregory added a comment -

        Patches welcome

        Show
        garydgregory Gary Gregory added a comment - Patches welcome
        Hide
        bludkiewicz Ben Ludkiewicz added a comment -

        Submitting patch.

        Show
        bludkiewicz Ben Ludkiewicz added a comment - Submitting patch.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit f56b284a54d9fcb7c0c2c1ed9ec8bca1d9f5b93e in logging-log4j2's branch refs/heads/master from Ben Ludkiewicz
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=f56b284 ]

        LOG4J2-1071 Allow for bufferSize=0 in SMTP appender. Apply patch with
        minor formatting changes.

        Show
        jira-bot ASF subversion and git services added a comment - Commit f56b284a54d9fcb7c0c2c1ed9ec8bca1d9f5b93e in logging-log4j2's branch refs/heads/master from Ben Ludkiewicz [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=f56b284 ] LOG4J2-1071 Allow for bufferSize=0 in SMTP appender. Apply patch with minor formatting changes.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit bc3e711d3e68deb0ebf2a83ea3cdf6929ee68217 in logging-log4j2's branch refs/heads/master from Gary Gregory
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=bc3e711 ]

        LOG4J2-1071 Allow for bufferSize=0 in SMTP appender. Add tests.

        Show
        jira-bot ASF subversion and git services added a comment - Commit bc3e711d3e68deb0ebf2a83ea3cdf6929ee68217 in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=bc3e711 ] LOG4J2-1071 Allow for bufferSize=0 in SMTP appender. Add tests.
        Hide
        garydgregory Gary Gregory added a comment -

        Thank you for the patch. Please provide unit tests next time.
        In Git master, please verify and close.

        Show
        garydgregory Gary Gregory added a comment - Thank you for the patch. Please provide unit tests next time. In Git master, please verify and close.

          People

          • Assignee:
            Unassigned
            Reporter:
            benjamin.jaton Benjamin Jaton
          • Votes:
            5 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development