Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Log4J when deploying an OSGi app with the Equinox Servle Bridge to Tomcat?

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?

like image 836
arturh Avatar asked Apr 01 '09 13:04

arturh


People also ask

Does Tomcat install log4j?

Apache Tomcat. Log4j may be used as the logging framework for Apache Tomcat. This support is implemented automatically by including the log4j-api, log4j-core, and log4j-appserver jars in the boot classpath.

Where should I set log4j2 formatMsgNoLookups to true?

You can do this: %m{nolookups} in the layout. {nolookups} is how you set the property log4j2. formatMsgNoLookups=true within the configuration XML content.


3 Answers

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.

like image 195
arturh Avatar answered Nov 08 '22 03:11

arturh


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

like image 3
nevh Avatar answered Nov 08 '22 03:11

nevh


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?

like image 2
toolkit Avatar answered Nov 08 '22 03:11

toolkit