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 Mufaddal Khumri <mu...@wmotion.com> on 2004/11/01 05:27:45 UTC
Re: Initializing log4j using a servlet question ..
Hi,
Thanks. Yes I found the same out yesterday.
log4j.appender.A1.file=${log.home}/cw.log was what was missing. I have
log.home pointing to /Tomcat/webapps/mywebapp/WEB-INF/log/
Now the other problem is about redirecting the exceptions like
NullPointerExceptions etc that get written to Tomcat/logs/catalina.out to
the ${log.home}/cw.log file. Is there a way to make Tomcat log all
exceptions resulting due to mywebapp to ${log.home}/cw.log??
Do I have to do something regarding this in the Tomcat server.xml file?
Following is an extract from the server.xml file. I have set the
swallowOutput = true for the Context of my webapp, but I do not know how
to redirect output to the ${log.home}/cw.log file (where log.home =
/Tomcat/webapps/mywebapp/WEB-INF/log/)
....
....
<Context path="/mywebapp" docBase="mywebapp" debug="0"
swallowOutput="true"
reloadable="true" crossContext="false">
<Logger className="org.apache.catalina.logger.FileLogger"
directory="webapps/mywebapp/WEB-INF/log" prefix="cw" suffix=".log"
timestamp="false"/>
</Context>
....
....
This logs in a file cw2004-10-30.log. But I want to log in the cw.log
file. Any tips as to how I could accomplish this?
Thanks.
> The appender is writing to a file that is located in the same directory
> that the VM started. How did you start Tomcat? If from one of the
> scripts in the CATALINA_HOME/bin directory, then that's where you log
> file will exist. If you started it as a service (and didn't do any
> special configuration to reset the location where the JVM starts), then
> (and I'm assuming Windows NT, 2k, or XP here) it will likely exist in
> c:\winnt\system32.
>
> If you want the appender to write the file to your configured location,
> then prefix the filename with the name of the system property you are
> setting, such as...
>
> log4j.appender.A1.file=${log.home}/cw.log
>
> I know this works in the XML config file. I'm not 100% sure properly
> substitution works in properties files, mostly because I never use
> them. But I would think this should work.
>
> Jake
>
> At 04:45 PM 10/29/2004 -0700, you wrote:
> >Hi,
> >
> >I am trying to use this under Tomcat 5.0.27.
> >
> >I have the following log4j.properties file under WEB-INF/conf/
> ># initialise root logger with level DEBUG and call it A1
> >log4j.rootLogger=DEBUG, A1
> ># set the appender to be FileAppender
> >log4j.appender.A1=org.apache.log4j.FileAppender
> >log4j.appender.A1.file=cw.log
> ># set set that layout to be SimpleLayout
> >log4j.appender.A1.layout=org.apache.log4j.SimpleLayout
> >
> >I have the following in my web.xml
> > <servlet>
> > <servlet-name>Log4jInitServlet</servlet-name>
> >
> <servlet-class>com.somepackage.Log4jInitServlet</servlet-class>
> > <load-on-startup>1</load-on-startup>
> > <init-param>
> > <param-name>log4j-configuration</param-name>
> > <param-value>conf/log4j.properties</param-value>
> > </init-param>
> > <init-param>
> > <param-name>log4j-log-path</param-name>
> > <param-value>WEB-INF/log</param-value>
> > </init-param>
> > </servlet>
> >
> >
> >I do the following in my Log4jInitServlet:
> >
> >...
> >String baseDir = getServletContext().getRealPath( "/" );
> >String logPath = config.getInitParameter(log4j-log-path);
> >logPath = baseDir + logPath;
> >File logPathDir = new File( logPath );
> >System.setProperty( "log.home", logPath );
> >PropertyConfigurator.configureAndWatch( confFile );
> >...
> >
> >When I start my tomcat engine, I do not get any exceptions but my log
> file does not get created? Am I missing something in my
> >log4j.properties file while specifying log4j.appender.A1.file ? or
> something else? I do not get any exceptions in catalina.out.
> >
> >I am trying to understand if this problem is due to my configuration
> of Tomcat or the configuration of my logger?
> >
> >Mufaddal Khumri
> >
> >
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org For
> additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org