geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Manu George" <>
Subject Re: Configuring log4j as jvm environment variable fails
Date Fri, 07 Nov 2008 11:38:05 GMT
Hi Hearty,

My understanding was that we just needed to hide the log4j and slf4j
classes to use logging
However a quick search came up with this

It lists the same problem and a solution

In case of wanting to use a properties file, You can configure log4j
for you app as follows

1) Write a gbean that will initialize log4j


package test

import java.util.Properties;

import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.log4j.PropertyConfigurator;

public class Log4JInitGBean {

	public Log4JInitGBean(String log4jResource, ClassLoader classloader)
			throws IOException {
		InputStream in;
		if (log4jResource != null) {
			in = classloader.getResourceAsStream(log4jResource);
			if (in == null) {
				throw new NullPointerException(
						"No log4j properties resource found at "
								+ log4jResource);
		} else {
		Properties props = new Properties();
		try {
		} finally {

	public static final GBeanInfo GBEAN_INFO;

	static {
		GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
		infoBuilder.addAttribute("log4jResource", String.class, true);
		infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
		infoBuilder.setConstructor(new String[] { "log4jResource",
				"classLoader" });

		GBEAN_INFO = infoBuilder.getBeanInfo();

	public static GBeanInfo getGBeanInfo() {
		return GBEAN_INFO;


Define this gbean in your plan via this entry

<gbean name="Log4jConfiguration" class="test.Log4JInitGBean">
       <attribute name="log4jResource"></attribute>

This will initialize ur log4j. Now since you are using slf4j as a
wrapper over log4j. You can hide the two projects that may already be
loaded in the parent classloaders via


Remember to package your own copies or add dependencies in your plan
for the slf4j and log4j jars
This should have your logging working.

2) Another way is to use the ApplicationLog4jConfigurationGBean though
I was not able to get it to work as expected

3) I was not getting log4j to initialize with the configuration I
specified without using the gbean above

I need to investigate more into 2 and 3.


P.S In your you can give the file path as
where org.apache.geronimo.server.dir is a system property

On Fri, Nov 7, 2008 at 4:10 PM, Hearty <> wrote:
> I have tried the below 2 options of setting my
> Both these options fails. I am not able to see log files created.
> JAVA_OPTS=-Dlog4j.configuration=C:\WebSphere\AppServerCommunityEdition\var\log\
> JAVA_OPTS=-Dorg.apache.geronimo.log4jservice.configuration=C:\WebSphere\AppServerCommunityEdition\var\log\
> These envionment variable I've specified from a command prompt and I've run
> start-server command from the same instance.
> My is as follows
> #attach an appender to the base apacheds package logger:
> #do not log apacheds to geronimo logs:
> #Configure the fp specific appender:
> log4j.appender.fp=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.fp.layout=org.apache.log4j.PatternLayout
> # geronimo style logging
> log4j.appender.fp.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
> log4j.appender.fp.append=true
> log4j.appender.fp.file=${org.apache.geronimo.server.dir}/var/log/fp.log
> log4j.appender.fp.bufferedIO=false
> #focal point specific log settings
> Please advice me where I went wrong
> --
> View this message in context:
> Sent from the Apache Geronimo - Users mailing list archive at

View raw message