3 messages in org.apache.logging.log4j-userRe: Pathing question
FromSent OnAttachments
Frank ZammettiJun 15, 2004 7:21 am 
Jacob KjomeJun 15, 2004 9:47 pm 
Frank ZammettiJun 16, 2004 7:17 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Pathing questionActions...
From:Jacob Kjome (ho@visi.com)
Date:Jun 15, 2004 9:47:24 pm
List:org.apache.logging.log4j-user

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