前往顾页
以后地位: 主页 > 精通Office > Ubuntu教程 >

log4j/Log4j2 建设根本教程

时候:2018-08-22 23:28来源:知行网www.zhixing123.cn 编辑:麦田守望者

Event Level LoggerConfig Level
 -- TRACE DEBUG INFO WARN ERROR FATAL OFF
ALL YES YES YES YES YES YES NO
TRACE YES NO NO NO NO NO NO
DEBUG YES YES NO NO NO NO NO
INFO YES YES YES NO NO NO NO
WARN YES YES YES YES NO NO NO
ERROR YES YES YES YES YES NO NO
FATAL YES YES YES YES YES YES NO
OFF NO NO NO NO NO NO NO

 
<?xml version="1.0" encoding="UTF-8"?>

<configuration debug="off" status="INFO"> <!-- 这个status是节制体系信息的输入级别 -->
<Properties>
<Property name="path">D:/logs</Property>
</Properties>

<Appenders>
<Console name="Console" target="SYSTEM_OUT"> <!-- 将日记信息从节制台输入 -->
<ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY" />
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5level %class{36}.%M()/%L - %msg%xEx%n" />
</Console>

<File name="debug" fileName="${path}/debug.log" append="true"> <!-- 将日记信息写入日记文件 -->
<Filters>
<!--节制台只输入level及以下级别的信息(onMatch),其他的直接回绝(onMismatch) -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY" />
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY" />
</Filters>
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5level %class{36}.%M()/%L - %msg%xEx%n" />
</File>

<RollingFile name="RollingFile" fileName="${path}/log.log" filePattern="${path}/log-%d{yyyy-MM-dd}_%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5level %class{36}.%M()/%L - %msg%xEx%n" />
<SizeBasedTriggeringPolicy size="50MB" />
</RollingFile>
</Appenders>

<Loggers>
<Root level="trace">
<AppenderRef ref="Console" /> <!-- 独一上述的Appenders建设还不敷,这里还不克不及少,少了就不会在节制台输入 -->
<AppenderRef ref="RollingFile" />
<AppenderRef ref="debug" /> <!-- 独一上述的Appenders建设还不敷,这里还不克不及少,少了就不会写入文件,但会建立文件 -->
</Root>
</Loggers>

</configuration>
 
log4j.rootLogger=debug,stdout,error

# set the output lever
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.Encoding=UTF-8
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout.ConversionPattern=[%p] - [%d{yyyy-MM-dd HH:mm:ss}] %F %m%n

# %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n

# set the Spring lever
log4j.category.org.springframework.beans.factory = DEBUG

### put the log to the file
log4j.appender.debug=org.apache.log4j.RollingFileAppender
log4j.appender.debug.File=../logs/debug.log
log4j.appender.debug.MaxFileSize = 10MB
log4j.appender.debug.Threshold = DEBUG
log4j.appender.debug.Encoding=UTF-8
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=[%p] - [%d{yyyy-MM-dd HH:mm:ss}] %F %m%n

### put the log to the file
log4j.appender.error=org.apache.log4j.RollingFileAppender
log4j.appender.error.File=../logs/error.log
log4j.appender.error.MaxFileSize = 10MB
log4j.appender.error.Threshold = ERROR
log4j.appender.error.Encoding=UTF-8
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=[%p] - [%d{yyyy-MM-dd HH:mm:ss}] %F %m%n

### output the sql
log4j.logger.com.pay.dao=DEBUG

### druid sql ###
log4j.logger.druid.sql=warn,stdout
log4j.logger.druid.sql.DataSource=warn,stdout
log4j.logger.druid.sql.Connection=warn,stdout
log4j.logger.druid.sql.Statement=warn,stdout
log4j.logger.druid.sql.ResultSet=warn,stdout

------分开线----------------------------
标签(Tag):log4j建设
------分开线----------------------------
保举内容
猜你感兴趣