log4j的日志
Posted pxzbky
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了log4j的日志相关的知识,希望对你有一定的参考价值。
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="off">
<Properties>
<Property name="ctx">dangbao</Property>
<Property name="dir">d:/app/logs</Property>
<!-- ${sys:java.io.tmpdir} d:/logs 以${logDir}方式引用-->
</Properties>
<CustomLevels>
<CustomLevel name="sysoprate" intLevel="350" />
</CustomLevels>
<Appenders>
<!--控制台输出-->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<!--回滚文件-->
<RollingFile name="RollingFile" fileName="${dir}/${ctx}/logs/${ctx}.log"
filePattern="${dir}/${ctx}/logs/${date:yyyy-MM}/${ctx}-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
<RollingFile name="druidRollingFile" fileName="${dir}/${ctx}/logs/${ctx}_druid.log"
filePattern="${dir}/${ctx}/logs/${date:yyyy-MM}/${ctx}_druid-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
</RollingFile>
<RollingFile name="shiro_oprate.log" fileName="${dir}/${ctx}/logs/${ctx}_shiro_oprate.log"
filePattern="${dir}/${ctx}/logs/${date:yyyy-MM}/${ctx}_shiro_oprate-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
<RollingFile name="sys_oprate_file" fileName="${dir}/${ctx}/logs/${ctx}_sys_oprate.log"
filePattern="${dir}/${ctx}/logs/${date:yyyy-MM}/${ctx}_sys_oprate-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
<RollingFile name="sys_user_oprate_file" fileName="${dir}/${ctx}/logs/${ctx}_sys_user_oprate.log"
filePattern="${dir}/${ctx}/logs/${date:yyyy-MM}/${ctx}_sys_user_oprate-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
<RollingFile name="druidStatLoggerFile" fileName="${dir}/${ctx}/logs/${ctx}_druidStatLogger.log"
filePattern="${dir}/${ctx}/logs/${date:yyyy-MM}/${ctx}_druidStatLogger-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
<RollingFile name="logistics_operate_log" fileName="${dir}/${ctx}/logs/${ctx}_logistics_operate_log.log"
filePattern="${dir}/${ctx}/logs/${date:yyyy-MM}/${ctx}_logistics_operate_log-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<!-- Async表示异步写日志,另起线程来写日志 -->
<AsyncRoot level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="RollingFile"/>
</AsyncRoot>
<!-- <AsyncLogger name="org.water.common.log" level="sysoprate"> -->
<!-- <AppenderRef ref="sys_oprate_file"/> -->
<!-- </AsyncLogger> -->
<AsyncLogger name="org.apache.shiro" level="info" additivity="false">
<AppenderRef ref="shiro_oprate.log"/>
</AsyncLogger>
<AsyncLogger name="org.water.common.log.BaseLog" level="info" additivity="false">
<AppenderRef ref="sys_oprate_file"/>
</AsyncLogger>
<!-- 系统用户后台操作日志 -->
<AsyncLogger name="user.oprate.log" level="info" additivity="false">
<AppenderRef ref="sys_user_oprate_file"/>
</AsyncLogger>
<!-- 自定义日志输出 -->
<!-- <AsyncLogger name="org.water.common.log.DruidStatLogger" level="info" >
<AppenderRef ref="druidStatLoggerFile"/>
</AsyncLogger> -->
<!-- durid日志输出 -->
<AsyncLogger name="com.alibaba.druid.pool.DruidDataSourceStatLoggerImpl" level="info" additivity="false">
<AppenderRef ref="druidStatLoggerFile"/>
</AsyncLogger>
<!-- sql性能 -->
<!-- <Logger name="druid.sql.Statement" level="debug" includeLocation="false">
<AppenderRef ref="Console"/>
<AppenderRef ref="druidRollingFile"/>
</Logger> -->
<!-- sql执行语句 -->
<AsyncLogger name="druid.sql" level="debug" additivity="false">
<AppenderRef ref="Console"/>
<AppenderRef ref="druidRollingFile"/>
</AsyncLogger>
<!-- 对外接口调用 -->
<AsyncLogger name="logistics.operate.log" level="info">
<AppenderRef ref="logistics_operate_log"/>
</AsyncLogger>
</Loggers>
</Configuration>
以上是关于log4j的日志的主要内容,如果未能解决你的问题,请参考以下文章