I think it would be useful to implement your solution as a configurable
parameter of an FileAppender. By default this delayFileCreation parameter
would be false so log4j performs the same as now. However you could set the
delayFileCreation parameter to true to cause the FileAppender to wait until
it's ready to log to create/open a file. Just my 2 cents worth.

On 8/29/07, James A. N. Stauffer <[EMAIL PROTECTED]> wrote:
>
> I would like the FileAppender to only create the file when about to
> write the first log.
>
> On 8/29/07, Niraj Patel <[EMAIL PROTECTED]> wrote:
> > Cheers for the confirmation. I would rather fix this with via the
> properties
> > file, but if that aint possible then a code fix will have to do.
> >
> > Anyone lese think this feature is something that should be overideable
> with
> > a parameter or something?
> >
> > Niraj
> >
> >
> >
> > On 8/29/07, James A. N. Stauffer <[EMAIL PROTECTED]> wrote:
> > >
> > > Log4j does creates files for every appender when initialized.  You
> > > could write your own appender to change that.
> > >
> > > On 8/29/07, Niraj Patel <[EMAIL PROTECTED]> wrote:
> > > > I have a log4j.xml file which is used by dozens of classes
> throughout
> > > the
> > > > day. One of these classes needs to log some data into a separate
> file,
> > > so I
> > > > created the following config:
> > > >
> > > > <appender name="XXX" class="
> org.apache.log4j.DailyRollingFileAppender">
> > > >     <param name="File" value="../logs/XXX.log"/>
> > > >     <param name="Append" value="true"/>
> > > >     <param name="DatePattern" value="'.'yyyy-MM-dd" />
> > > > </appender>
> > > >
> > > > <category name="a.b.c.XXXClass">
> > > >     <appender-ref ref="XXX" />
> > > > </category>
> > > >
> > > > Although the XXX.log file is written to disk (albeit empty) every
> time
> > > the
> > > > log4j engine is initialised by the other classes.
> > > >
> > > > Am I correct in saying that the Log4J engine will parse all
> appenders
> > > and
> > > > write any log files not on disk, to disk?
> > > >
> > > > Is there a way to stop this? I only want the log file to be written
> onto
> > > > disk when XXXClass logs data.
> > > >
> > > > Cheers in advance,
> > > >
> > > > Niraj
> > > >
> > >
> > >
> > > --
> > > James A. N. Stauffer        http://www.geocities.com/stauffer_james/
> > > 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]
> > >
> > >
> >
>
>
> --
> James A. N. Stauffer        http://www.geocities.com/stauffer_james/
> 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]
>
>

Reply via email to