views:

1554

answers:

3

When deploying my OSGi web application using the equinox servlet bridge i get the following:

log4j:WARN No appenders could be found for logger (org.springframework.osgi.extender.internal.activator.ContextLoaderListener).
log4j:WARN Please initialize the log4j system properly.

I tried several ways of supplying the necessary "log4j.properties" file, including:

  • adding the context-param "log4jConfigLocation" to the servlet bridge web.xml
  • creating a folder "classes" in the WEB-INF folder and copying my log4j.properties file there (and copying it in several other locations)
  • removing my log4j bundle and setting "extendedFrameworkExports" to org.apache.log4j so (I guess) the tomcat log4j is used ... this did not work because my dependencies need some slf4j classes which are provided as a fragment for the log4j bundle ... which isn't there anymore ...

Of course I also have a fragment bundle which extends the log4j bundle with a log4j.properties file, but it looks like this log4j bundle is not used.

ADDED: I should add that I'm developing the application in Eclipse... and my fragment bundle which configures log4j / slf4j works there.

Has anyone solved this? Any ideas?

+1  A: 

UPDATE: This doesn't really help with your issue...

I am just researching OSGi myself.

Not quite what you're looking for, but the following post discusses the same issue when using vanilla equinox (ie: not hosted within tomcat/jetty).

It suggests creating a 'fragment bundle' (example available for download) to hold your log4j.properties. Perhaps you could try something similar?

Or perhaps you just need to place the log4j.properties inside META-INF of your WAR?

toolkit
1. the fragment bundle approach you usually take does apparently not work when you deploy your application to tomcat as a .war. 2. my war didn't have a META-INF folder yet, but I tried and it also does not work (i've tried all existing folders like WEB-INF, WEB-INF/eclipse, ...)
arturh
sorry I couldn't be more help..
toolkit
+1  A: 

I found my error. The fragment which should provide the log4j.properties file did not include it, because I did not add it to the binary build in build.properties.

arturh
+2  A: 

Thanks arturh. I had the same issue. I added log4j.properties to my /src folder.

Neville Harrison
Following up to this, I had a subsequent issue where, while my application bundles were logging via the log4j configuration fragment successfully, other bundles were not. The solution was to ensure that those bundles had org.apache.log4j in their "Import-Package:" attribute, even though they didn't explicitly need the import for compilation. They then found my log4j.properties file via the fragment, hosted by the log4j bundle.
Neville Harrison
Thanks for the tip! Glad I could be of assistance.
arturh