Quoting Jitendra Kharche <[EMAIL PROTECTED]>:

> Hi Jake,
>
> Thanks. The way you have suggested is another good way. But my problem
> is little different. I want to use a system variable in the path of log
> file. If I do using your method, it will still be a hardcoded path
> because once I code it in the ServletContextListener, I can not change
> it on the fly during the installation of my product.

How so?...

In web.xml...

    <context-param>
        <param-name>log-path</param-name>
        <param-value>/path/to/log/directory</param-value>
        <description>
        Log Path picked up by Log4jServletContextListener
        </description>
    </context-param>

Now in your context listener, you just do...

System.setProperty("log.path", context.getInitParameter("log-path"));

In log4j.xml...

<param name="File" value="${log.path}/myLog.log"/>

You can override the web.xml <context-param> using server-specific deployment
descriptors such as Tomcat's Context Configuration File...

<Context ....>
  <Parameter name="log-path" value="/path/to/deployer-specified/log/directory"
override="false"
        description="Override web.xml value so that deployer has control over
context param, not the developer.  Note that 'override=false' means 'don't
allow web.xml to override the value I'm setting here, not the other way
around'"/>
</Context>

> I don't want to
> keep my log files in the webserver deployment directory. The log files
> are kept somewhere else e.g. C:\myapp\logs. For this, as I have
> explained in my first mail, I set a system variable MY_APP=C:\myapp and
> this path depends on the installation directory which e.g. on unix can
> be \home\usr\myapp. I can extend your suggestion to set this path in a
> configuration file or in servelt init parameters, read from there and
> set it. But this makes redundant information for the variable MY_APP. It
> is defined in system variables as well as in my configurations.
> I want to use "the system environment variable" to specify the path of
> my log file.
> Any more suggestion are welcome.
>

I think what I suggested above should work fine.  Notice that even if the log
path changes, the deployer has full control over the location of the log file
by being able to override web.xml <context-param>'s so there is no need to make
changes to the .war file even if the log file path changes.  Just have the
deployer make the decision at deployment time using the server's proprietary
configuration.  That's what all the indirection is about in J2EE's
configuration scheme; to make things flexible for cases like this.


Jake

> Regards,
> Jitendra
>
>
> -----Original Message-----
> From: Jacob Kjome [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, April 19, 2005 9:09 PM
> To: Log4J Users List
> Subject: RE: How to specify log file path using env variable
>
> Quoting Jitendra Kharche <[EMAIL PROTECTED]>:
>
> > Hi Paul,
> >
> > Thanks for the help.
> > This is the best way fot standalone java applications. Whereas I am
> > having a web application and I don't want to change the startup script
>
> > of webserver.
> >
> > Is there any other way?
> >
>
> Sure.  If you are using a webapp, just create a ServletContextListener
> and as the first thing in the contextInitialized() method, set the
> system property.
> Then perform manual Log4j configuration.  Note that you might want to
> put a dummy log4j.xml file in WEB-INF/classes to avoid autoconfiguration
> finding a Log4j config file elsewhere in the classpath (assuming that
> you don't put your log4j.xml file for manual configuration in the
> classpath, which probably makes sense since the system property
> refrences wouldn't be resolved before autoconfiguration).
>
> Jake
>
> > Regards,
> > Jitendra
> >
> > -----Original Message-----
> > From: Paul Smith [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, April 19, 2005 12:49 PM
> > To: Log4J Users List
> > Subject: Re: How to specify log file path using env variable
> >
> > if you start your application and set the property via the standard
> > java system property, it works fine.
> >
> > eg.
> >
> > java -classpath <blah> -DMY_APP=c:\myapp  ....
> >
> > Then you can embed the MY_APP in your log4j configuration file.
> >
> > cheers,
> >
> > Paul
> >
> > Jitendra Kharche wrote:
> >
> > >Hi All,
> > >
> > >I am using log4j for looging my applocation log on windows. The log
> > >file path I have specified in the log4j.xml file is currently a
> > >windows
> >
> > >path e.g. C:\myapp\logs\myapp.log.
> > >I want to remove the hardcoded path (C:\myapp) and replace it with a
> > >system environment variable MY_APP (=C:\myapp). How can I do that?
> > >Furthermore, this will help me in migration my application from
> > >windows
> >
> > >to unix or other OSs.
> > >
> > >Please help.
> > >
> > >Regards,
> > >Jitendra Kharche
> > >
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>




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

Reply via email to