dcsimg
How to store the log file with web application path?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   walker_skyinn
Posted On:   Monday, February 24, 2003 06:33 AM

In local, I can use :
log4j.appender.file.File=d:\myweb\logs\log.txt
to store the log file under my web application path,
but I didn't know how to store it in server with a NOT absolute path,
By tomcat, if I use:
log4j.appender.file.File=logs\log.txt
the log file will store in $TOMCAT_PATH$/bin folder,
but I want it store in d:/myweb folder.
so It's problem with my web application!

Is there some method such as:
log4j.appender.file.File=<$WEB_PATH$>\logs\log.txt
or others?

thank you very much:)

Re: How to store the log file with web application path?

Posted By:   Gert_Cuppens  
Posted On:   Saturday, April 19, 2003 06:06 AM

It's almost 2 months since you wrote this, so I suppose I'm too late.
Nevertheless, I'll send you a piece of code I found in "professional Apache Tomcat", from Wrox.

You need an initialisation servlet in which you write :
String path = getServletContext().getRealPath("/");
String properties = path + getInitParameter("properties");
PropertyConfigurator.configure(properties);

Via getServletContext you get the full path of the servlet. You add to this the name of the properties-file which you have defined in your web.xml like this :

org.brukkerlin.servlets.EddiLog4jServlet
org.brukkerlin.servlets.EddiLog4jServlet

properties
WEB-INFclasseslog4j.properties

1


And then you need a log4j.properties file, in which you write :

# definitie van simple logger
# level van de logger is DEBUG (dus op één na hoogste; hoogste = ALL)
log4j.logger.eddi.simple=DEBUG, simple

#definitie van de appender : bepaalt naar waar de logging geschreven wordt
log4j.appender.simple=org.apache.log4j.FileAppender
log4j.appender.simple.File=C:Program FilesApache GroupTomcat 4.1logseddi.log

#bepalen van de layout
log4j.appender.simple.layout=org.apache.log4j.SimpleLayout
About | Sitemap | Contact