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 Frank Zammetti <fz...@hotmail.com> on 2004/06/15 16:21:23 UTC
Pathing question
Hello all. I'm using Log4J within a Struts-based application running under
Tomcat. I configure Log4J when the app starts up within a Struts plug-in
via XML file. Here's my config file...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %C{2} %x - %m\n" />
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.FileAppender">
<param name="Threshold" value="ERROR"/>
<param name="File" value="toaerror.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %C{2} %x - %m\n" />
</layout>
</appender>
<appender name="TOAAGINGFILE" class="org.apache.log4j.FileAppender">
<param name="Threshold" value="DEBUG"/>
<param name="File" value="toaAgingError.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %C{2} %x - %m\n" />
</layout>
</appender>
<category name="com.mycompany" additivity="true">
<priority value="trace" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</category>
<category name="com.mycompany.toa.daemonthreads.AgingProcessDaemonThread"
additivity="true">
<priority value="trace" />
<appender-ref ref="TOAAGINGFILE" />
</category>
</log4j:configuration>
Now, this all works fine, so even if you spot something wrong in there, it
can probably be ignored for the time being :)
The issue I'm facing is that the log files get created in /tomcat/bin.
Previously I had real paths in the config file instead of just the
filenames, but we are going to be moving to a new hosting environment, and I
am not yet familiar with the directory structures, so I wanted to write this
config file in a generic way. But as it is now, there doesn't seem to be
any way to tell before-hand where the logs are goingt o wind up being
written within a given environment. /tomcat/bin/ isn't the ideal location,
clearly.
So, here's my question... how can I specify relative paths in the config
file, assmuing I can, and what will it be relative to?
What I'd really like to do is have a /log directory under the /WEB-INF/
directory in my webapp, that would be ideal, or else a /log/ directory in
the root of my webapp, but bottom line is that ideally I'd like the logs to
be somewhere within my webapp. Is there a way to specify such a location,
WITHOUT it being tied to real paths? Even if it's not something in the
config file itself, is there some code change I could make to do this, i.e.
some sort of Log4J parameter to set before loading the config file? Just
guessing here.
My fallback is to re-write the XML on-the-fly from my plug-in, adding the
path at runtime before initializing Log4J (I'm assuming I can get that
information somehow, but that's another problem!), but I'm really hoping the
is a better answer than that.
Thanks in advance everyone!
Frank
_________________________________________________________________
Watch the online reality show Mixed Messages with a friend and enter to win
a trip to NY
http://www.msnmessenger-download.click-url.com/go/onm00200497ave/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Pathing question
Posted by Jacob Kjome <ho...@visi.com>.
At 10:21 AM 6/15/2004 -0400, you wrote:
>What I'd really like to do is have a /log directory under the /WEB-INF/
>directory in my webapp, that would be ideal, or else a /log/ directory in
>the root of my webapp, but bottom line is that ideally I'd like the logs
>to be somewhere within my webapp. Is there a way to specify such a
>location, WITHOUT it being tied to real paths? Even if it's not something
>in the config file itself, is there some code change I could make to do
>this, i.e. some sort of Log4J parameter to set before loading the config
>file? Just guessing here.
Yep, there is. See...
http://nagoya.apache.org/wiki/apachewiki.cgi?Log4JProjectPages/AppContainerLogging
Particularly, see the links for InitContextListener. Read the Javadoc for
instructions. Basically, what you do is define the following in a file
appender configured in log4j.xml...
<param name="File" value="${myapp.log.home}/daily.log"/>
Where "myapp" is the name of your context. A system property will be
dynamically created with this naming pattern. I figured that since
context's are unique in the container, setting the system variable based on
the context name should be unique. The path for this will default to
WEB-INF/logs of your context (assuming that it has a writable
directory). You can also specify a custom log path which will be used in
place of the default. For that matter, you can specify what the system
property should be named which holds the value of the log path, but I think
the default works fine and is one less thing to have to mess with. BTW,
you also specify a repository selector so that your app will be guaranteed
not to step on others even if Log4j is in a global classloader. You really
should use the ContextJNDISelector, not the ContextClassLoaderSelector
To use this for yourself, make sure to check out the "LOG4J_SANDBOX_ALPHA3"
tag from logging-log4j-sandbox because ContextJNDISelector was removed from
the HEAD of the sandbox (and moved to Log4j proper with heavy modification
for Log4j-1.3), but exists in said tag.
Jake
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org