0

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

hudi
  • 15,555
  • 47
  • 142
  • 246

1 Answers1

0

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>
Eric B.
  • 23,425
  • 50
  • 169
  • 316
  • yes I try but there is no better sollution ? I want to specify about 10 package and when log4j2 is better then first one I will expect more elegant sollution – hudi Oct 22 '14 at 13:53
  • Not to my knowledge, other than that all subloggers inherit the same logger definitions (ex: everything under org.my.project.* will all use the same logger definition for org.my.project unless otherwise specified) – Eric B. Oct 22 '14 at 13:59
  • but I want to log information from 3rd party libraries like org.springframework, org.wicket and so on so in log4j I can do this with one clever and readeble sentence and in log4j2 I need to do this horrible something – hudi Oct 22 '14 at 14:04
  • I disagree. I find XML configuration much easier to read than the .properties style in log4j. But you define them the same way here - just create a logger definition for each. No one said that XML is less verbose. – Eric B. Oct 22 '14 at 14:14