log4j2配置

由于项目需要,将log4j升级到log4j2,升级过程异常艰难,通过半天的摸索,终于解决了。现记录已备后用:

class 类中方法:Logger requestlog = LogManager.getLogger("locationinterface");

log4j2配置文件:log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingFile name="locationinterface"
fileName="d:locationinterface/locationinterface.log"
filePattern="d:llocationinterface/$${date:yyyy-MM}/locationinterface-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB" />
</Policies>
</RollingFile>


<RollingFile name="locationplan" fileName="d:locationplan/locationplan.log"
filePattern="d:llocationplan/$${date:yyyy-MM}/locationplan-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console" />


</Root>


<Logger name="locationinterface" level="DEBUG">
<AppenderRef ref="locationinterface" />
</Logger>
<Logger name="locationplan" level="DEBUG">
<AppenderRef ref="locationplan" />
</Logger>
</Loggers>
</Configuration>


经验:

  创建RollingFile 时,必须filePattern="d:llocationinterface/$${date:yyyy-MM}/locationinterface-%d{MM-dd-yyyy}-%i.log.gz" 否则不能正常将内容写入log文件中



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值