You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Reto Bachmann-Gmuer <re...@gmuer.ch> on 2003/02/12 12:53:54 UTC

loggin to $TOMCAT_HOME/logs in webapp

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello

I'd like to log to the standart log directory of the servlet container,  
is there a generic way to do this? My webapp should log there by  
default without requiring server configuration.

I found a way that works with tomcat 4.1 but it sure won't work with  
other servlet-container. So I'm looking for a better solution

Thanks for your help!

Reto



This is my init-servlet

/**
  * adapted from example at  
http://jakarta.apache.org/log4j/docs/manual.html
  */
public class Log4jInit extends HttpServlet {

	public void init() {
		try {
			URL configIn =
			getServletContext().getResource(
				"/WEB-INF/conf/log4j.properties");
			
			File logFile = new  
File(System.getProperty("catalina.base",System.getProperty("user.home")) 
, "logs/mies-server.log");

			Properties properties = new Properties();
			properties.load(configIn.openStream());
			
			//add mies-specific config
			 
properties.put("log4j.appender.MIES","org.apache.log4j.RollingFileAppend 
er");
			properties.put("log4j.appender.MIES.File",logFile.getAbsolutePath());
			properties.put("log4j.appender.MIES.MaxFileSize","1000KB");
			properties.put("log4j.appender.MIES.MaxBackupIndex","0");
			 
properties.put("log4j.appender.MIES.layout","org.apache.log4j.PatternLay 
out");
			properties.put("log4j.appender.MIES.layout.ConversionPattern","%p %t  
%c - %m%n");

			//load config
			PropertyConfigurator.configure(properties);
		} catch (IOException ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex.toString());
		}
	}

	public void doGet(HttpServletRequest req, HttpServletResponse res) {
	}
}

and this is my log4.properties in the webpapps WEB-INF/conf dir:

#the target MIES is a special appender that point to the file  
TOMCAT_HOME/logs//mies-server.log
log4j.rootLogger=info, stdout, MIES
# Example of switching on debug level logging for part of tree
log4j.logger.org.wymiwyg.mies.server=debug, MIES
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (Darwin)

iD8DBQE+SjXbD1pReGFYfq4RAv+YAKCcAm2/KPDKYXiM9kjh7eky0OXRwACdHvse
T5oP0ZfJPoMb2O7Zpueagsk=
=aJfs
-----END PGP SIGNATURE-----


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