geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Woods <dwo...@apache.org>
Subject Re: Configuring log4j as jvm environment variable fails
Date Tue, 18 Nov 2008 18:06:36 GMT
Manu, I opened GERONIMO-4418 to reference this as a possible Sample we 
could create for 2.2.


-Donald


Manu George wrote:
> 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
> 
> http://webui.sourcelabs.com/geronimo/mail/user/threads/Logging_in_Geronimo_2.0.1.meta
> 
> 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
> 
> eg:
> 
> package test
> 
> import java.io.IOException;
> import java.io.InputStream;
> 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 {
> 			return;
> 		}
> 		Properties props = new Properties();
> 		try {
> 			props.load(in);
> 		} finally {
> 			in.close();
> 		}
> 		PropertyConfigurator.configure(props);
> 	}
> 
> 	public static final GBeanInfo GBEAN_INFO;
> 
> 	static {
> 		GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
> 				Log4JInitGBean.class);
> 		infoBuilder.setPriority(2);
> 		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">fp-log4j.properties</attribute>
>   </gbean>
> 
> 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
> 
>  <sys:hidden-classes>
>       <sys:filter>org.apache.log4j</sys:filter>
>       <sys:filter>org.slf4j</sys:filter>
>     </sys:hidden-classes>
> 
> 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.
> 
> Regards
> Manu
> 
> P.S In your log4j.properties you can give the file path as
> log4j.appender.FILE.file=${org.apache.geronimo.server.dir}/var/log/test.log
> where org.apache.geronimo.server.dir is a system property
> 
> 
> On Fri, Nov 7, 2008 at 4:10 PM, Hearty <heartyraphael@gmail.com> wrote:
>> I have tried the below 2 options of setting my fp-log4j.properties.
>> Both these options fails. I am not able to see log files created.
>>
>> SET
>> JAVA_OPTS=-Dlog4j.configuration=C:\WebSphere\AppServerCommunityEdition\var\log\fp-log4j.properties
>>
>> SET
>> JAVA_OPTS=-Dorg.apache.geronimo.log4jservice.configuration=C:\WebSphere\AppServerCommunityEdition\var\log\fp-log4j.properties
>>
>> These envionment variable I've specified from a command prompt and I've run
>> start-server command from the same instance.
>>
>> My fp-log4j.properties is as follows
>>
>> #attach an appender to the base apacheds package logger:
>> log4j.logger.org.apache.directory=INFO,fp
>> #do not log apacheds to geronimo logs:
>> log4j.additivity.org.apache.directory=false
>>
>>
>> #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
>> log4j.logger.com.telelogic.focalpoint=DEBUG
>> log4j.logger.com.telelogic.focalpoint.dao.jdbc.Jdbc=OFF
>> log4j.logger.com.telelogic.focalpoint.dao.ViewExecutor=OFF
>> log4j.logger.org.apache.catalina=INFO
>> log4j.logger.org.springframework=INFO
>> log4j.logger.net.sf.ehcache.distribution=INFO
>>
>> Please advice me where I went wrong
>> --
>> View this message in context: http://www.nabble.com/Configuring-log4j-as-jvm-environment-variable-fails-tp20378195s134p20378195.html
>> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>>
>>
> 

Mime
View raw message