如何告诉log4j没有Web容器?

问题描述

我们有一个Eclipse / SWT客户端,我们正在使用log4j2。我们得到以下日志条目

2020-09-24 07:17:01,769 main INFO Log4j appears to be running in a Servlet environment,but there's no log4j-web module available. If you want better web container support,please add the log4j-web JAR to your web archive or server lib directory.

这样做的原因是,我们导入servlet-api以利用open feign来实现与服务器的REST通信。开放式伪装使用的接口带有servlet-api注释。

因此,按照Why Log4j thinks my project run in Servlet Environment中的建议删除servlet-api来摆脱该消息对我们不起作用。

这真令人讨厌,因为log4j2以此填充了我们的日志。

我们如何摆脱此信息?

解决方法

由于此日志是由log4j2本身生成的,因此您可能希望将log4j的内部日志级别从 INFO 提升到 WARN

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

<Appenders>
...

..

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...