Endre,
Thanks to a recent contribution by Yoav Shapira, log4j can pick up any env-entry value specified in web.xml
and perform variable substitution.
In web.xml ==========
<env-entry> <env-entry-name>BASE</env-entry-name> <env-entry-value>/some/path/</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry>
In your config file ===================
<configuration>
<jndiSubstitutionProperty name="BASE"/>
<appender name="A" class="org.apache.log4j.FileAppender>
<param name="File" value="${BASE}/log.txt"/>
...
</appender>
..
</configuration>If you are using log4j 1.3-alpha5, the directive is
<jndiSubstitutionProperty jndiName="BASE"/>
In CVS head, this was changed to:
<jndiSubstitutionProperty name="BASE"/>
I think the above provides an answer to your requirements quoted below.
At 03:09 PM 1/17/2005, Endre St�lsvik wrote:
A feature that I'd -really- appreciate from the servlet-spec, is some kind of "log-dir" variable, that log4j could use as root for its configuration. In one of our apps, I've made a special variable that is set by the app to the mandatory servlet container provided "temp dir", unless you've set it yourself: $<productname>.log.dir. Using this, you can now configure all your file appenders relatively. If you don't provide the variable using -D switches (or whatever), you get the logfiles in the temp dir, while if you do set it, you'll get them where you want. This is nice - the log files do have somewhere to go in any case. (Another feature I'd love, is -extremly- simple: a way to know the context name (the "specific subset of the server's URL namespace") when the application is starting up, typically from the ServletContext. Now you only get it when a request actually comes in. This in particular related to the logging, logfile-location and config-location. ServletContext javadoc: There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as /catalog and possibly installed via a .war file.) )
Endre
-- Ceki G�lc�
The complete log4j manual: http://www.qos.ch/log4j/
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
