Quoting Jitendra Kharche <[EMAIL PROTECTED]>:

>
> Hi Jacob,
>
> I appreciate your response. Sorry for the delay to reply back since I
> was out of the town for last 4 days.
> I am sorry, your solution does not fit my requirement as it is. But it
> gave me a clue to do it the way I want.
>
> I did it as follows:
> 1. Set a system environment variable MY_APP=C:\myapp
> 2. Added a ServletContextListener in my application, and in
> contextInitialized method I get the value of this environment variable
> in a variable myAppHome and set this varibale in jvm properties so that
> I can access it whenever required (I need it for different purposes) as
> you specified
>       System.setProperty("MY_APP", myAppHome);

If you already set it as a system property, such as -DMY_APP=c:\myapp, why would
you need to re-set it again in code?  You can already access it as a system
property from anywhere in the JVM.  The only thing I see your context listener
doing is making sure a "\" gets added to the end of the path if it doesn't
already exist.  Otherwise, it isn't doing anything useful, but maybe I'm
missing something that your EnvironmentReader class is doing?


> 3. In the log4j properties file, now I have specified the file path
> using this property
>       <param name="File" value="${MY_APP}/logs/myLog.log"/>
>

Yup, that's the idea.

> Thanks a lot. I did this because, for some reason I don't want to
> complicate the application configuration and avoid it from becoming app
> server dependant e.g. today I am working with Websphere and I don't know
> how to do Context configuration in that. You had given example for
> Tomcat. Event though I find out this file in Webshphere, tomorrow if we
> migrate to WebLogic then the deployer has to look for some other file.
> And also my installtion document also has to reflect all these issues.
> Anyway thanks a lot again.
>

Keep in mind the reason I suggested the solution I did was because, I'm pretty
sure said that you didn't have access to the server to set system variables (-D
params) on the command line at application startup.  Now you seem to be saying
you *are* able to do that?  Misconmmunication?

> But I am afraid, this is not working. The log file is not created. Am I
> doing something wrong. Attaching log4j.xml file and source files below.
> Please reply back if you find any flow in my solution.
>

Does the ${MY_APP}/logs/ directory actually exist?  Log4j won't create it if it
doesn't already exist.  This is not a bug, but expected and correct behavior. 
Log4j should not be in the business of creating directories in arbitrary places
on your filesystem.  If you want to log to that directory, then make sure to
create it.  A good place to do this would be in your context listener class.


Jake



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

Reply via email to