log4j father Logger and son logger

Source: Internet
Author: User
Tags log4j

The purpose of a logger is to be able to do so under a certain range (a class or a package), and the output of the log is different from the way the log is exported elsewhere.


log4j.properties

<strong><span style= "FONT-SIZE:14PX;" 
>log4j.rootlogger = Debug,stdout,d #log4j. Debug=ture//whether to turn on log4j internal Journal Printing # (Consoleappender: Console printing)
Log4j.appender.stdout = Org.apache.log4j.ConsoleAppender Log4j.appender.stdout.Target = System.out Log4j.appender.stdout.layout = Org.apache.log4j.PatternLayout Log4j.appender.stdout.layout.ConversionPattern = [%- 5p]%d{yyyy-mm-dd hh:mm:ss,sss} method:%l%n%m%n # (dailyrollingfileappender) LOG4J.APPENDER.D =
Org.apache.log4j.DailyRollingFileAppender Log4j.appender.d.file = G://logs/log.log Log4j.appender.d.append = True
Log4j.appender.d.threshold = DEBUG Log4j.appender.d.layout = org.apache.log4j.PatternLayout Log4j.appender.d.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m%n # (mail) log4j.appender.ma
Il=org.apache.log4j.net.smtpappender Log4j.appender.mail.threshold=debug log4j.appender.mail.buffersize=10 Log4j.appender.mail.From = 123@qq.com log4j.appender.mail.smtphost=smtp.qq.com log4j.appender.mail.Subject=LOG4J message log4j.appender.mail.smtpusername=123 log4j.appender.mail.smtppassword=xxx log4j.appender.mail.To=
456@qq.com Log4j.appender.mail.layout=org.apache.log4j.patternlayout LOG4J.APPENDER.MAIL.LAYOUT.CONVERSIONPATTERN=[%-5P]%d (%r)--> [%t]%l:%m%x%n #配置子logger to control a certain range of log output,

For example, the child logger here is to control the log output of all classes under the Cn.server.test package, and its parent logger is Rootlogger log4j.logger.cn.server.test=error,e
Log4j.additivity.cn.server.test=false//LOG4J.APPENDER.E = Org.apache.log4j.DailyRollingFileAppender 
Log4j.appender.e.file =g://logs/error.log Log4j.appender.e.append = True Log4j.appender.e.threshold = Error Log4j.appender.e.layout = Org.apache.log4j.PatternLayout Log4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd HH:MM:SS} [%t:%r]-[%p]%m%n

configuration Logger, the purpose is to control a certain range of log output, such as the child logger here is to control the Cn.server.test packet under the log output of all classes, its Father logger is rootlogger.

Log4j.logger.cn.server.test=error,e


used in the Cn.server.test package.

Logger Logger = Logger.getlogger (Xxx.class)
when you get the Logger object and then use the Logger object for log input, logger will find the child logger here according to the Xxx.class's full class name .
Log4j.logger.cn.server.test=error,e
class outside the Cn.server.test package, you can also use the
Logger Logger = Logger.getlogger ("Cn.server.test");
specifically, this child logger is specified for log output.

additivity Properties for


         log4j: Indicates whether the child logger is to output the log in the parent logger's appender, and if Additivity is set to false, the child logger will only output in its own appender, not in the logger of the parent appender.

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.