The main use of threshold.
Threshold's Grammar
Log4j.threshold=level
Level is the previous said off, FATAL, ERROR, WARN, INFO, DEBUG, all. Threshold is a global filter that filters out information that is below the level set.
Look at an example:
Log4j.rootlogger=debug, CON.
Log4j.appender.con=org.apache.log4j.consoleappender
Log4j.appender.con.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.CON.LAYOUT.CONVERSIONPATTERN=[%T]%-5p%c-%m%n
#Only Print Log statement of level WARN or above regardless of (print only information at WARN levels)
#logger.
Log4j.threshold=warn
The use of threshold is flexible and can be added to the appender threshold
Log4j.rootlogger=debug, C
Log4j.appender.c=org.apache.log4j.consoleappender
# Set The appender threshold to INFO
Log4j.appender.c.threshold=info
Log4j.appender.c.layout=org.apache.log4j.patternlayout
log4j.appender.c.layout.conversionpattern=%-4r [%t]%-5p%c%x-%m%n
This initial setting level is debug, but Log4j.appender.c.threshold=info is set to INFO. Because Info>debug so if the DEBUG level information is included, it will be filtered.
Log4j.rootlogger=debug, stdout, R Log4j.appender.stdout=org.apache.log4j.consoleappender Log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.layout.conversionpattern=[%d] [%4p]%l%m%n log4j.appender.r=org.apache.log4j.rollingfileappender LOG4J.APPENDER.R.ENCODING=GBK Log4j.appender.r.threshold=info Log4j.appender.r.file=cohl_elearning.log. oil//applications//cohlelearning//cohlelearning//log4j.appender.r.maxfilesize= 2048KB Log4j.appender.r.maxbackupindex=20 Log4j.appender.r.layout=org.apache.log4j.patternlayout LOG4J.APPENDER.R.LAYOUT.CONVERSIONPATTERN=[%D] [%t] [%4p]%l%m%n
Java code
Public class Testjava {static Logger Logger = Logger.getlogger (testjava.class);/** * @param args */public static Voi D main (string[] args) {loggertest ();} public static void Loggertest () {logger.info ("logger info"); Logger.debug ("Logger Debug "); Logger.error ("logger error"); } }