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:Frank Zammetti (fzam@hotmail.com)
Date:Jun 16, 2004 7:17:49 am
List:org.apache.logging.log4j-user

That's awesome, thank you!

Now I have to go remove my hack job... Last night I wound up writing code that would read in the Log4J XML config file and find the filenames, then append the path to the log files at that point (which I figured out how to get at runtime from within my startup plug-in). That works fine, but obviously what you've sent is far more elegant and worth the time to change to do it right. Thanks again!

Frank

From: Jacob Kjome <ho@visi.com>

Reply-To: "Log4J Users List" <log4@logging.apache.org> To: "Log4J Users List" <log4@logging.apache.org> Subject: Re: Pathing question Date: Tue, 15 Jun 2004 23:47:46 -0500

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.