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.