logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael <sg...@gmx.net>
Subject Reasonable approach to configure log4j in a web app environment
Date Fri, 16 Nov 2007 23:33:19 GMT
Hi,

I am quite new to log4j and made some simple steps to understand log4j.

I've noticed that log4j does *not* reconfigure on config file change 
unless I tell him programmatically with 
PropertyConfigurator#configureAndWatch. Well, this situation is quite 
unpleasant since I wanted to configure my l4j env completely with 
properties/xml files and *not* programmatically.

I've searched the list but couldn't gain any good information to use.

Is there some possibility to tell log4j in the props file something like 
'log4j.watch=true'?

Another issue is that I want to reuse the same props file on different 
webapps and there is no built-in possibility to tell within the context:

log4j.appender.mystuff.File=${catalina.home}/logs/${contextName}.log

???

Since I didn't find any built-in solution to the problems above, I have 
to create a contextlistener which configures those parts at startup.

my ServletContextListener would look like:

	public void contextInitialized(ServletContextEvent sce) {
		
		// I really dislike this option and would really like rely on the 
automatic property discovery
		String path = 
sce.getServletContext().getRealPath("/WEB-INF/classes/log4j.properties");
		PropertyConfigurator.configureAndWatch(path);
		
		String contextName = sce.getServletContext().getServletContextName();
		//and now?? how do I tell, for instance the appender "mystuff" to use 
#setFile("${catalina.home}/logs/"+contextName+".log")
		//there is no way to retreive a declared fileappender by name, is there?

	}

System.setProperty("contextName",contextName);

Can't be set obviously.

Any help will be appreciated!

Mike
-- 
<NO> OOXML - Say NO To Microsoft Office broken standard
http://www.noooxml.org

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message