You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk> on 2004/03/03 10:33:54 UTC

Where to store log files from packed WAR file apps

Hello

Now that I've got my Ant build/deploy scripts working nicely, I'm tempted to
start running my applications out of packed WAR files.

I cannot figure out if there is a *portable* way to specify paths for where
my Log4J log files should be saved.

I assume I could use the 'catalina.home' property to save the logs under the
Tomcat installation directory - but that's Tomcat specific.

Has anyone got around this, somehow, or is it a case of getting Ant to glue
things with some hard-coded values at build time?

Many thanks for any contributions.

Harry Mantheakis
London, UK


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


Re: Where to store log files from packed WAR file apps

Posted by Jacob Kjome <ho...@visi.com>.
You should never log to within the directory structure of your webapp if you
want your app to be portable.  Provide configuration in web.xml as to where you
want the log file to go which an admin can override via proprietary
configuration.  For instance, in Tomcat...

<Context ...>
    <Parameter name="log4j-log-location" value="C:\logs" override="false"
        description="Location for logs to be written"/>
</Context>

Then in your Log4j initialization, use value of the "log4j-log-location"
context-param and set a system property with that value to a name that you
reference in your log4j.xml file such as....

<appender name="File" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="${log.location}" />
..
..
..
</appender>


Or, check out the logging-log4j-sandbox project and grab the alpha_2 (I think
that's the tag name) tag.  Then look into ServletContextLogAppender which will
allow you to specify this in log4j.xml....

<appender name="ServletContext"
class="org.apache.log4j.servlet.ServletContextLogAppender">
        <param name="servletContextPath" value="/mycontext" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%-5p][%-8.8t]: %39.39c{3} -
%m"/>
        </layout>
    </appender>

The output will be routed through your server's context.log() mechanism.  In
Tomcat, just set up....
<Context path="/mycontext" docBase="mycontext.war"
         debug="5" reloadable="true">

    <Logger
        className="org.apache.catalina.logger.FileLogger"
        prefix="localhost_mycontext_servlet_log."
        suffix=".txt"
	    timestamp="true" />
</Context>

Now you don't need to configure any file to do the logging.  It will just show
up in your container's log directly which you know for a fact will exist and the
container will create it for you.

Or, use Chainsaw2...
http://logging.apache.org/log4j/docs/chainsaw.html

Jake


Quoting Harry Mantheakis <ha...@mantheakis.freeserve.co.uk>:

> Hello
> 
> Now that I've got my Ant build/deploy scripts working nicely, I'm tempted to
> start running my applications out of packed WAR files.
> 
> I cannot figure out if there is a *portable* way to specify paths for where
> my Log4J log files should be saved.
> 
> I assume I could use the 'catalina.home' property to save the logs under the
> Tomcat installation directory - but that's Tomcat specific.
> 
> Has anyone got around this, somehow, or is it a case of getting Ant to glue
> things with some hard-coded values at build time?
> 
> Many thanks for any contributions.
> 
> Harry Mantheakis
> London, UK
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

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