can control
the rate at which log events are processed, once maximum limit has been
reached, subsequent log events are discarded silently.
Following are
the Burst Filter Parameters.
Parameter
|
Type
|
Description
|
level
|
String
|
Level of
messages to be filtered. Anything at or below this level will be filtered out
if maxBurst has been exceeded. The default is WARN meaning any messages that
are higher than warn will be logged regardless of the size of a burst.
|
rate
|
float
|
The
average number of events per second to allow.
|
maxBurst
|
integer
|
The
maximum number of events that can occur before events are filtered for
exceeding the average rate. The default is 10 times the rate.
|
onMatch
|
String
|
Action to
take when the filter matches. May be ACCEPT, DENY or NEUTRAL. The default
value is NEUTRAL.
|
onMismatch
|
String
|
Action to
take when the filter does not match. May be ACCEPT, DENY or NEUTRAL. The
default value is DENY.
|
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="warn" name="MyApp" packages=""> <Appenders> <Console name="my_console_appender" target="SYSTEM_OUT"> <BurstFilter level="INFO" rate="16" maxBurst="100" /> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="my_console_appender" /> </Root> </Loggers> </Configuration>
package log4j_tutorial; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class HelloWorld { private static final Logger logger = LogManager.getLogger(); public static void main(String args[]) throws InterruptedException { logger.trace("Trace Message!"); logger.debug("Debug Message!"); logger.info("Info Message!"); logger.warn("Warn Message!"); logger.error("Error Message!"); logger.fatal("Fatal Message!"); } }
Run
HelloWorld application, you will get following output.
15:01:37.985 [main] TRACE log4j_tutorial.HelloWorld - Trace Message! 15:01:37.986 [main] DEBUG log4j_tutorial.HelloWorld - Debug Message! 15:01:37.986 [main] INFO log4j_tutorial.HelloWorld - Info Message! 15:01:37.986 [main] WARN log4j_tutorial.HelloWorld - Warn Message! 15:01:37.986 [main] ERROR log4j_tutorial.HelloWorld - Error Message! 15:01:37.986 [main] FATAL log4j_tutorial.HelloWorld - Fatal Message!
No comments:
Post a Comment