Log4j different levels of input to different files

Source: Internet
Author: User
Tags log4j

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"); } }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.