如何在log4j2中指定日志文件

如何在log4j2中指定日志文件

本文介绍了如何在log4j2中指定日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在log4j中,我可以这样指定文件:

In log4j I can specify file like this:

log4j.additivity.org.springframework.ws.server.MessageTracing=false
log4j.logger.org.springframework.ws.server.MessageTracing=TRACE, AUDIT
log4j.additivity.org.springframework.ws.client.MessageTracing=false
log4j.logger.org.springframework.ws.client.MessageTracing=TRACE, AUDIT

当我要登录名为AUDIT的附加程序时.

when I want to log into appender named AUDIT.

如何将其重写为log4j2 xml配置?

How should I rewrite this into log4j2 xml configuration?

更新

我已经定义了root记录器,例如:

I have defined root logger like:

    <Root level="error">
        <AppenderRef ref="console" />
        <AppenderRef ref="syslog" />
    </Root>

和一些我想登录到应用程序文件的类.在log4j中:

and some of class I want to log into app file. In log4j:

log4j.logger.org.springframework=WARN, APP
log4j.logger.org.my.project=DEBUG, APP

但是在log4j2中,我不知道如何用一句话重写

but in log4j2 I have no idea how to rewrite in in one sentence

推荐答案

您是否尝试过以下操作(您需要先定义"app"附加程序):

Have you tried something like the following (you need to first define your "app" appender):

   <Appenders>
    <File name="app" fileName="logs/app.log">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
    </File>
  </Appenders>

然后定义记录器的附加程序:

Then define your logger's appender:

<logger name="org.my.project" level="debug">
   <appender-ref ref="app" />
</logger>

这篇关于如何在log4j2中指定日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:40