views:

1009

answers:

2

I'm running JBoss 4.2.3.GA, and have a web app that uses Spring and Log4j. I've set up Spring's Log4jConfigurer, but am having a problem since JBoss's log4j file is not on the classpath. It's at jboss.home/server/defaul/conf/jboss-log4j.xml. So, without hard-coding the path in Log4jConfigurer, how can I get Spring to use JBoss's log4j file?

A: 

You don't generally modify JBoss's log4j config via the applications, that's a route to madness. JBoss uses a shared configuration amongst all apps.

You can, however, programmatically alter log4j's runtime configuration, such as adding custom appenders or loggers. This isn't what Spring's Log4jConfigurer is for, however - you use that to configure a standalone log4j config.

skaffman
Right, I'm trying to avoid using my own log4j.xml file and only use JBoss's jboss-log4j.xml and modify it by adding appenders and categories. That I do by hand. Now, I want my web-app to read that file, or rather I want my web-app to tell Spring (via Log4jConfigurer) to read that file and use it for its configuration.
Gary Kephart
Any application deployed within JBoss will automatically use its log4j config. Just use log4j from your app, and it should just work. The app doesn't need to configure log4j itself.
skaffman
Normally, that is the case. However, with Spring there's an issue. I believe it's because there's a log4j.xml within the spring.jar files. Therefore, you have to tell Spring to look somewhere else for the configuration. See http://firstpartners.net/kb/index.php/Spring_Pointer_to_Log4j_Configuration_File
Gary Kephart
Sounds like you're packaging the wrong JAR files, there's no log4j config in the runtime JARs. Which JAR have you found this in?
skaffman
A: 

Do answer your question: JBoss usually sets additional system properties that point to the server directory and configuration directories. You should be able to access these from your application or let them be resolved from the spring contexts.

In your case, it should be ok to access ${jboss.server.home.dir}/conf/jboss-log4j.xml

As skaffman correctly pointed out in a comment, there is no need to configure Spring to read JBoss' log4j configuration unless you have otherwise adapted something in the packaging. You will only have to take care that no log4j.[properties,xml] lies somewhere in the root of the classpath or that a component tries to configure Log4J "manually".

Hope this could help,
Kariem

Kariem