I've already tried the ServletContextListener solution but it doesnt work as I
could imagine since the logger already read the props file.
> The only solution that comes to my mind if you want to set the property even
> before log4j is started is to set it through the java command as i mentioned
> in my earlier mail. However, if you want to set the property when your
> application is *getting deployed*, then there appears to be another way to do
> this. You can have a *startup servlet* in your application which will set
> this system property. Something like:
>
> web.xml:
> -------------
> <servlet>
> <servlet-name>MyConfigServlet</servlet-name>
> <servlet-class>org.myapp.MyConfigServlet</servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
> Then the code in your startup servlet(MyConfigServlet.java) would look like:
>
> public void init(ServletConfig config) throws ServletException {
> System.setProperty("myWebApp","somepath");
> }
>
> This would mean that when your application is being deployed the variable
> value will be set.
> Now, comes the tricky part. Since the log4j is already configured before
> coming to your servlet, the change to the myWebApp variable(which is refered
> in some appender) will have to be reflected to log4j.
> You can something like:
> Logger.getRootLogger().getLoggerRepository().resetConfiguration();
> This would tell log4j to configure itself again afresh and this time your
> myWebApp property is already set.
> So your startup servlet would ultimately look like:
>
> public void init(ServletConfig config) throws ServletException {
> System.setProperty("myWebApp","somepath");
> Logger.getRootLogger().getLoggerRepository().resetConfiguration();
> }
>
> This approach does have a drawback:
> - When you invoke the resetConfiguration() method some of the log files
> will get cleared(if the append is set to false on those appender
> configuration) and hence you will lose the previously logged data.
>
> regards,
> -Jaikiran
>
>
>
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Yes, this could be a solution I've already tried it, but I wonder whether
> is possible to set a SystemProperty before log4j is even loaded so that
> FileAppender.file=${myWebAppVariable}\${logfileName}
>
> does make sense.
>
> I'm just imagine a ClassLoader workaround but I can't see anything concrete.
>
> > If you always deploy to the same location under the app server you
> > could check if that is a property for the app server (i.e.
> > catalina.home) that you could use as your base.
> >
> > On 7/24/06, [EMAIL PROTECTED] wrote:
> > > Hi everyone,
> > > I'd like that classes running in a web application would log to a file
> > > whose path is local to the absolute path where the web app is running.
> > > This means that, named ${myWebApp} my web application, I'd like to define
> > > the FileAppender file property to
> > > ${myWebApp}'s absolute path . I've tried doing this by creating a
> > > ServletContextListener implementation and declaring in it a
> > > SystemProperty, but it doesnt work so far: i mean, it works but not the
> > > very first time that the web app rises, and this happens because class
> > > loader loads the log4j.jar before the ContextListener had called,I
> > > presume. Any hints are appreciated
> > >
> > > Ign Rome, Italy
> > >
> > >
> > > ___________________________________________________________________
> > > Conto Arancio al 4% fino a fine 2006 - Zero spese, soldi sempre
> > > disponibili. Aprilo subito
> > > http://click.libero.it/ING
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > James Stauffer
> > Are you good? Take the test at http://www.livingwaters.com/good/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> ___________________________________________________________________
> Conto Arancio al 4% fino a fine 2006 - Zero spese, soldi sempre disponibili.
> Aprilo subito
> http://click.libero.it/ING
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
> ---------------------------------
> Find out what India is talking about on Yahoo! Answers India.
___________________________________________________________________
Conto Arancio al 4% fino a fine 2006 - Zero spese, soldi sempre disponibili.
Aprilo subito
http://click.libero.it/ING
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]