logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin Jaton <benjamin.ja...@gmail.com>
Subject SMTP appender + filter
Date Thu, 25 Jun 2015 22:39:15 GMT
Hello,

I am trying to create a filter at the appender level that would show all
the messages that contain "Show".
This is my test:

        LogManager.getLogger(Test.class).debug("Hide me!");
        LogManager.getLogger(Test.class).info("test");
        LogManager.getLogger(Test.class).debug("Show me (debug)");
        LogManager.getLogger(Test.class).fatal("Hide me! (fatal)");
        LogManager.getLogger(Test.class).info("Show me (info)");
        LogManager.getLogger(Test.class).info("Hide me!");

And this is the configuration:

<Configuration status="debug" name="MyApp" packages="">
  <Appenders>
    <SMTP name="Mail" subject="Error Log" to="..." from="..."
smtpProtocol="..." smtpHost="..." smtpPort="..." smtpUsername="..."
smtpPassword="..." bufferSize="1">
        <RegexFilter regex=".*Show.*" onMatch="ACCEPT" onMismatch="DENY"/>
        <PatternLayout>
            <pattern>%5p %m%n</pattern>
        </PatternLayout>
    </SMTP>
  </Appenders>
  <Loggers>
    <Root level="info">
      <AppenderRef ref="Mail"/>
    </Root>
  </Loggers>
</Configuration>

This produces 1 email with:
---------------------------------------
  FATAL Hide me! (fatal)
  INFO Show me (info)
---------------------------------------

I would expect 2 emails with:
---------------------------------------
  INFO test
  DEBUG Show me (debug)
---------------------------------------
  FATAL Hide me! (fatal)
  INFO Show me (info)
---------------------------------------

I also tried this composite filter instead:
        <Filters>
          <ThresholdFilter level="TRACE" onMatch="NEUTRAL"
onMismatch="DENY" />
          <RegexFilter regex=".*Show.*" onMatch="ACCEPT" onMismatch="DENY"/>
        </Filters>

But same result, the DEBUG event is not triggering the appender somehow.

Anyone has an idea how to do this?


Bonus question: Since bufferSize can't be set to 0, is it not possible to
only include the log message itself in the email?

Many thanks!
Ben

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message