How to specify log file in log4j2

2019-09-02 04:23发布

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

when I want to log into appender named AUDIT.

How should I rewrite this into log4j2 xml configuration?

UPDATE

I have defined root logger like:

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

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

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

标签: java log4j
1条回答
Summer. ? 凉城
2楼-- · 2019-09-02 04:46

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>
查看更多
登录 后发表回答