log4j / slf4j package-based logging, how to handle frameworks, e.g. spring?

223 Views Asked by At

Let's say my application consists of several components which are logged separately:

myapp.log
myapp-foo.log
myapp-bar.log

My classes all define a "standard" java logger:

private static final Logger logger = LogManager.getLogger(ThisClass.class);

Logging for components "foo" and "bar" is set up via package-based configuration (each of which logs to it's own logfile) :

<Logger name="com.mycompany.myapp.foo" level="info">
    <AppenderRef ref="foo"/>
</Logger>

<Logger name="com.mycompany.myapp.bar" level="info">
    <AppenderRef ref="bar"/>
</Logger>

This works fine, up to the point where we want to see log messages from a framework we use, such as spring, since spring log statements end up in myapp.log - not myapp-foo.log or myapp-bar.log.

It's convenient to have one log4j.xml or log4j2.xml file, but can we use package-based log configuration in this way - and still have spring log statements logged to the "correct" log file, myapp-foo.log of myapp-bar.log?

Or is there a different solution?

Edit: we are using spring 4.0.3.RELEASE and log4j2

0

There are 0 best solutions below