At 04:04 AM 12/27/2006, you wrote:
>On 12/27/06, chuanjiang lo <[EMAIL PROTECTED]> wrote:
>>
>> I am using PropertyConfigurator.configure in the Listener class
>>
>>  PropertyConfigurator.configure(event.getServletContext
>> ().getRealPath("")+"/WEB-INF/foo.xml");
>>

2 things...

1. Never ever use this. Always load as a resource. As I stated before, the servlet spec makes no guarantee that you will be a "real path". If your webapp is served directly from the .WAR file instead of an "exploded" WAR, getRealPath("/") will return null. Instead use context.getResource("/WEB-INF/foo.xml"). This will return a URL, which you can pass to the configure() method that takes a URL. See...

http://java.sun.com/j2ee/sdk_1.2.1/techdocs/api/javax/servlet/ServletContext.html#getResource(java.lang.String)

2. You can't use PropertyConfigurator with an XML config file. Use DOMConfigurator for XML config files

>> Log4j is picking up foo.xml, However it seems like the logging events does
>> not behave as what foo.xml specifies. Nothing has changed.
>> Appreciate any kind advice.
>
>
>
>Learnt the mistake here.
>I should be using DOMConfigurator.configure()
>

Depends on what your config is. If this works, it means you have a log4j.xml somewhere in the classpath and it is using that for configuration. This is clearly not what you want because your config file is named "foo.xml" and it doesn't even exist in the classpath. You are picking up someone elses config file. What you should be doing is calling configure(myFooXMLURL) with the URL you loaded (see above).

>One thing i notice for PropertiesConfigurator
>
>for e.g.
> Properties props = new Properties();
>props.put("admin-console-abs-home", path);
> in = this.getClass().getClassLoader().getResourceAsStream("foo.properties
>");
>props.load(in);
> PropertyConfigurator.configure(props);
>
>In this case in foo.properties, we are able to use ${admin-console-abs-home}
>as a variable.
>Is there any method for DOMConfigurator?
>

The only difference between the 2 configurators, as far as property references are concerned, is that you can't define the property inside the XML file where you can inside the properties file. However, in both cases, you can reference the property inside the respective config files. so, your property reference of ${admin-console-abs-home} will work in both cases.


Also note what one responder mentioned. If you defined a system property, it is available to all applications. I suggest that any property you set either generically named *and* generically points to a single location where you are ok with any app running within the container logging to this directory OR name your properties very specifically, such as "fooApp.log.home", where "fooApp" is the name of a specific application. Naming your properties specifically reduces the chance that you will clash with other apps that might be setting or depending on their own properties.

What I suggest is that you just log to tomcat's default logging directory. Tomcat already sets ${catalina.home} and ${catalina.base} properties. I suggest using the latter (read up on Tomcat to find out why). This will simplify your life. If you refer to these properties to provide the directory for logging, then you don't need to mess with any manual log4j config process nor do you need to set a custom -D parameter to specify your logging home. Just put your log4j.xml or log4j.properties (use those names, specifically) in WEB-INF/classes and log4j.jar in WEB-INF/lib and you are done.


Jake

Jake



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to