log4j2打印出spring和struts2的日志

最近web项目使用了log4j2,但发现无法打印spring和struts2的日志,然后查了下官方文档,描述如下:

Using Log4j 2 in Web Applications

You must take particular care when using Log4j or any other logging framework within a Java EE web application. It's important for logging resources to be properly cleaned up (database connections closed, files closed, etc.) when the container shuts down or the web application is undeployed. Because of the nature of class loaders within web applications, Log4j resources cannot be cleaned up through normal means. Log4j must be "started" when the web application deploys and "shut down" when the web application undeploys. How this works varies depending on whether your application is a Servlet 3.0 or newer or Servlet 2.5 web application.

In either case, you'll need to add the log4j-web module to your deployment as detailed in the Maven, Ivy, and Gradle Artifacts manual page.

To avoid problems the Log4j shutdown hook will automatically be disabled when the log4j-web jar is included.


按照官网的说法,web项目在一般java项目的基础上添加log4j-web、servlet升级至3.0以上即可,但是操作完还是不行,折腾了很久,原来还需要加入jcl包,在此记录一下。

加入log4j2所需要的包如下:

log4j-core-2.5.jar、log4j-api-2.5.jar、log4j-web-2.5.jar、log4j-jcl-2.5.jar


参考官方文档:

http://logging.apache.org/log4j/2.x/


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

succeedloveaaaa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值