log4j:WARN找不到记录器的附加程序(org.springframework.web.context.support.StandardServletEnvironment)

克莱伯·莫塔(Kleber Mota)

我正在尝试在我的spring项目中配置log4j,但是在pom.xml中包含以下内容之后:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

这个文件log4j2.xml在我的类路径中:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

当我部署应用程序时,此消息显示在控制台中(没有日志消息):

log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我访问了指示的链接,但是其中的信息对我没有帮助。

有人知道我想念什么吗?

ps:在我的课程中,我也添加了这一行:

static final Logger logger = LogManager.getLogger(AcessoService.class.getName());

并添加:

logger.error(...);

在我想要的位置,但正如我所说,控制台中没有显示日志消息。

更新

现在,我将文件名更正为log4j.xml,错误消息更改为:

log4j:WARN Continuable parsing error 2 and column 30
log4j:WARN O elemento-raiz do documento "Configuration" deve corresponder à raiz de DOCTYPE "null".
log4j:WARN Continuable parsing error 2 and column 30
log4j:WARN O documento é inválido: nenhuma gramática encontrada.
log4j:ERROR DOM element is - not a <log4j:configuration> element.

更新2

下面的文件纠正了第二个错误,但我返回了我在此处发布的第一个错误:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>
混乱的

新错误与log4j.xml文件的内容有关。您的根Configuration元素没有名称空间声明:

<log4j:configuration debug="true"
                     xmlns:log4j="http://jakarta.apache.org/log4j/">

能帮上忙吗?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章