You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Ja...@web.de on 2009/05/04 14:56:54 UTC

Access logfile logger

Hi,

I'm using log4j with a DailyRollingFileAppender. Now I want to add some reporting functions to the same application that uses this appender. So I need to get access to the logfile that is written by the file appender. Only the current logfile needs to be read so is is possible via the logger instance?

Logger logger = Logger.getLogger(this.class);

Regards,
Jason


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Access logfile logger

Posted by Yair Ogen <ya...@gmail.com>.
I think the approach should be via the appender. you can try and extend it -
AFAIK only the appender can give you the file name.

On Mon, May 4, 2009 at 3:56 PM, <Ja...@web.de> wrote:

> Hi,
>
> I'm using log4j with a DailyRollingFileAppender. Now I want to add some
> reporting functions to the same application that uses this appender. So I
> need to get access to the logfile that is written by the file appender. Only
> the current logfile needs to be read so is is possible via the logger
> instance?
>
> Logger logger = Logger.getLogger(this.class);
>
> Regards,
> Jason
>
>
> ______________________________________________________
> GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://movieflat.web.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Access logfile logger

Posted by Simon Park <si...@yahoo.co.uk>.
Hi Jason,

What are your requirements for "reporting functions"?  Do you need to discover statistics about the current log file?  I'm guessing, but it seems that the most useful statistic might be the current size of the log file.  I've outlined a possible way you might be able to get at that.

The RollingFileAppender uses the org.apache.log4j.helpers.CountingQuietWriter to keep track of the number of characters written to the FileOutputStream.  DailyRollingAppender doesn't use the CountingQuietWriter, it uses a QuietWriter instead.  So maybe you could extend DailyRollingAppender: you could override the setQWForFiles(:Writer) method to use the CountingQuietWriter instead of the QuietWriter.  At that point you may fairly easily expose a method that will give you the current character count.

NB the CountingQuietWriter is not thread-safe, so if you want to access this property of the appender from a separate thread, you'll have to provide a synchronized version of the CountingQuietWriter (I've already written one of these - let me know if you'd like the source).

Cheers,

Simon




________________________________
From: "JasDA@web.de" <Ja...@web.de>
To: log4j-user@logging.apache.org
Sent: Monday, 4 May, 2009 13:56:54
Subject: Access logfile logger

Hi,

I'm using log4j with a DailyRollingFileAppender. Now I want to add some reporting functions to the same application that uses this appender. So I need to get access to the logfile that is written by the file appender. Only the current logfile needs to be read so is is possible via the logger instance?

Logger logger = Logger.getLogger(this.class);

Regards,
Jason


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org