Thanks for all you guys. I will have a try.
2010/12/30 Tushar Kapila <tgkp...@gmail.com>

> I think for most apps you would want all logs to go to file so you can
> see start up exceptions. Only place you might not mind missing this is
> when no app specific common code runs before this servlet inits.
> So my advice is customize the log4j xml in file system per install.
> That way all logs will be in file.
>
> On 12/29/10, Jacob Kjome <h...@visi.com> wrote:
> > Log4j will attempt to auto-configure itself by looking for "log4j.xml"
> and
> > then
> > "log4j.properties" in the root of the claspath upon the first call to
> > getLogger().
> >  And yes, this may very well be before your init servlet runs.  Note that
> > the new
> > configuration (done manually in the init servlet) will have things
> > configured as
> > you want them.
> >
> > There is a solution.  You can set system properties....
> >
> > -Dapppath=/my/logging/directory
> >
> > And, optionally....
> > -Dlog4j.configuration=file:///path/to/log4j.properties
> >
> >
> > That said, you could just place a minimal config file in the classpath
> > pointing
> > all logging to the Console and then let your init servlet configure the
> > preferred
> > config file as you are doing.  I guess it all depends on how important it
> is
> > for
> > you to get all logging to your preferred file, even logging that occurs
> > prior to
> > your init servlet running.
> >
> >
> > Jake
> >
> > On 12/27/2010 12:26 AM, maven apache wrote:
> >> Hi:
> >>
> >> I want the logs created by log4j put under the app dir,so I set the
> >> placeholder in the log4j.properties:
> >>
> >> # chartstdout is set to be a ConsoleAppender.
> >> log4j.appender.chartstdout=org.apache.log4j.ConsoleAppender
> >> log4j.appender.chartstdout.layout=org.apache.log4j.PatternLayout
> >> log4j.appender.chartstdout.layout.ConversionPattern=%-4r [%t] %-5p %l %x
> -
> >> %m%n
> >>
> >>
> >> log4j.appender.chartfileout=org.apache.log4j.FileAppender
> >> log4j.appender.chartfileout.File=${apppath}/logs/log.html
> >> log4j.appender.chartfileout.Append=true
> >> log4j.appender.chartfileout.layout=com.test.util.CustomHTMLLayout
> >>
> >> log4j.rootLogger=debug, chartstdout,chartfileout
> >>
> >> Then in my servlet whose "load-on-startup" attribute is "0" I set the
> >> property "apppath",but it does not work.
> >> It seems that the log4j read the log4j.properties and config the log
> >> before
> >> I modify the property.
> >>     public void init() {
> >>         DbManager.init();
> >>         // log
> >>         String context =
> >> getServletConfig().getServletContext().getRealPath("/");
> >>         Properties p = new Properties();
> >>         p.setProperty("apppath", context);
> >>         try {
> >>
> >> p.load(InitServlet.class.getResourceAsStream("/log4j.properties"));
> >>         } catch (IOException e) {
> >>             e.printStackTrace();
> >>         }
> >>         PropertyConfigurator.configure(p);
> >>     }
> >>
> >>
> >>
> >> Of course,I can rename the log4j.properties,then the log4j will not find
> >> the
> >> file but I can. However some other libs which I used in my appliction
> >> require log4j also,they need the log4j.properties to generate there
> logs.
> >>
> >> Any ideas?
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >
> >
>
> --
> Sent from my mobile device
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>

Reply via email to