You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Alex Rosenbaum <Al...@thomsonreuters.com> on 2008/09/25 21:54:19 UTC

TimeBased + SizeBased

I am trying to implement logging to rolling files. I want rollover to
occur when the size reaches certain limit. At the same time I'd like
file name to include date stamp, so the result looks like:
 
MyLog.2008-09-08.log
MyLog.2008-09-08.1.log
MyLog.2008-09-08.2.log
... etc.
 
I started with log4cxx::RollingFileAppender, but it doesn't seem to
support FileName patterns.
Next, I tried log4cxx::rolling::RollingFileAppender with
TimeBasedRollingPolicy. This option does not allow rollover to be
triggered by file size.
Next, I tried log4cxx::rolling::RollingFileAppender with
TimeBasedRollingPolicy and SizeBasedTriggeringPolicy, but it seemed to
create a conflict because TimeBasedRollingPolicy also sets Triggering
policy for the appender.
 
What is the solution I am looking for?
 
Alex Rozenbaum
Consultant


Thomson Reuters 

Phone: 646-822-2821

alex.rosenbaum@thomsonreuters.com
thomsonreuters.com


 


This email was sent to you by Thomson Reuters, the global news and information company.
Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters.


Re: TimeBased + SizeBased

Posted by Dale King <da...@gmail.com>.
On Mon, Sep 29, 2008 at 12:54 PM, Alex Rosenbaum <
Alex.Rosenbaum@thomsonreuters.com> wrote:

>  Dale,
>
> Thank you anyway, appreciate what you are trying to do here.
>

Note, I am not part of the Log4Cxx project at all. I am just a user that
banged my head against some things over the summer adopting Log4CXX. All I
am trying to do here is help others.

The bit of difficulty I had was that TimeBasedRollingPolicy cannot be used
just as a triggering policy. It can be used just as a rolling policy as I
described. What I wanted was rollover every day, but only keep the last n
days worth of logs.
-- 
Dale King

RE: TimeBased + SizeBased

Posted by Alex Rosenbaum <Al...@thomsonreuters.com>.
Dale,
 
many thanks for your reply. I agree with all your notes about policy
behaviours.
 
For the last couple of days I've been trying to achieve the needed
behavior by using SizeBasedTriggeringPolicy in combination with
subclassed FixedWindowRolling policy.
 
You were right, it did not work that easy. First, as many other classes,
FixedWindowRolling policy has all its members private, so subclassing it
is a challenge. Try changing pattern formatter. It expectes to find
Integer Formatter and if it does not find it, it throws an exceptions. 
 
I resorted into subclassing RollingPolicyBase and putting most of
existing Fixed Window code into my new class. I had a problem with few
base apr features that are not exported from the dll, like
RolloverDescription and FileRenameAction. I has to include their source
code into my project to fix that. 
 
At the end I think I'd be better off putting all my classes inside of
log4cxx, which probably sends you a signal about its design.
 
Thank you anyway, appreciate what you are trying to do here.
 
ar

________________________________

From: Dale King [mailto:dalewking@gmail.com] 
Sent: Monday, September 29, 2008 11:52 AM
To: Log4CXX User
Subject: Re: TimeBased + SizeBased


Also if you eliminated the .n part of the filename and just went with
date and time as the filename then you could do it with
TimeBasedRollingPolicy as the rolling policy and
SizeBasedTriggeringPolicy as the triggering policy. There should be no
conflict.

Using this your filenames would be like:


MyLog.2008-09-08_01_23_57_AM.log
MyLog.2008-09-08_05_37_04_PM.log

You would need to choose a time resolution that was shorter than the
time it takes to exceed the size. If you don't you will keep logging to
the same log file even though the size is exceeded.


On Mon, Sep 29, 2008 at 11:28 AM, Dale King <da...@gmail.com> wrote:


	You can't with log4cxx as it exists. You don't want
TimeBasedRollingPolicy. You want SizeBasedTriggeringPolicy with
FixedWindowRollingPolicy. But FixedWindowRollingPolicy only supports the
index format specifier. If you subclassed FixedWindowRollingPolicy  and
overrode getFormatSpecifiers to be something like this:
	
	  PatternMap specs;
	  RULES_PUT("i", IntegerPatternConverter);
	  RULES_PUT("index", IntegerPatternConverter);
	  RULES_PUT("d", FileDatePatternConverter);
	  RULES_PUT("date", FileDatePatternConverter);
	  return specs;
	
	You could get close. I'll bet though it probably will not work
completely like you think it will. For instance it will only start a new
log file when the size is exceeded. So if there are few messages you
could have the same log file for weeks.
	
	I think there is definitely some room for improvement in the
area of policies. For example, TimeBasedRollingPolicy cannot be used as
a triggering policy unless it is also the rolling policy. If you do,
once it triggers it will trigger for every message thereafter.
	
	
	On Thu, Sep 25, 2008 at 3:54 PM, Alex Rosenbaum
<Al...@thomsonreuters.com> wrote:
	

		I am trying to implement logging to rolling files. I
want rollover to occur when the size reaches certain limit. At the same
time I'd like file name to include date stamp, so the result looks like:
		 
		MyLog.2008-09-08.log
		MyLog.2008-09-08.1.log
		MyLog.2008-09-08.2.log
		... etc.
		 
		I started with log4cxx::RollingFileAppender, but it
doesn't seem to support FileName patterns.
		Next, I tried log4cxx::rolling::RollingFileAppender with
TimeBasedRollingPolicy. This option does not allow rollover to be
triggered by file size.
		Next, I tried log4cxx::rolling::RollingFileAppender with
TimeBasedRollingPolicy and SizeBasedTriggeringPolicy, but it seemed to
create a conflict because TimeBasedRollingPolicy also sets Triggering
policy for the appender.
		 
		What is the solution I am looking for?
		 
		Alex Rozenbaum
		Consultant
		

		Thomson Reuters 

		Phone: 646-822-2821

		alex.rosenbaum@thomsonreuters.com
		thomsonreuters.com
		

		 

		This email was sent to you by Thomson Reuters, the
global news and information company.
		Any views expressed in this message are those of the
individual sender, except where the sender specifically states them to
be the views of Thomson Reuters. 




	-- 
	Dale King
	




-- 
Dale King



This email was sent to you by Thomson Reuters, the global news and information company.
Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters.


Re: TimeBased + SizeBased

Posted by Dale King <da...@gmail.com>.
Also if you eliminated the .n part of the filename and just went with date
and time as the filename then you could do it with TimeBasedRollingPolicy as
the rolling policy and SizeBasedTriggeringPolicy as the triggering policy.
There should be no conflict.

Using this your filenames would be like:

MyLog.2008-09-08_01_23_57_AM.log
MyLog.2008-09-08_05_37_04_PM.log

You would need to choose a time resolution that was shorter than the time it
takes to exceed the size. If you don't you will keep logging to the same log
file even though the size is exceeded.

On Mon, Sep 29, 2008 at 11:28 AM, Dale King <da...@gmail.com> wrote:

> You can't with log4cxx as it exists. You don't want TimeBasedRollingPolicy.
> You want SizeBasedTriggeringPolicy with FixedWindowRollingPolicy. But
> FixedWindowRollingPolicy only supports the index format specifier. If you
> subclassed FixedWindowRollingPolicy  and overrode getFormatSpecifiers to be
> something like this:
>
>   PatternMap specs;
>   RULES_PUT("i", IntegerPatternConverter);
>   RULES_PUT("index", IntegerPatternConverter);
>   RULES_PUT("d", FileDatePatternConverter);
>   RULES_PUT("date", FileDatePatternConverter);
>   return specs;
>
> You could get close. I'll bet though it probably will not work completely
> like you think it will. For instance it will only start a new log file when
> the size is exceeded. So if there are few messages you could have the same
> log file for weeks.
>
> I think there is definitely some room for improvement in the area of
> policies. For example, TimeBasedRollingPolicy cannot be used as a triggering
> policy unless it is also the rolling policy. If you do, once it triggers it
> will trigger for every message thereafter.
>
> On Thu, Sep 25, 2008 at 3:54 PM, Alex Rosenbaum <
> Alex.Rosenbaum@thomsonreuters.com> wrote:
>
>>  I am trying to implement logging to rolling files. I want rollover to
>> occur when the size reaches certain limit. At the same time I'd like file
>> name to include date stamp, so the result looks like:
>>
>> MyLog.2008-09-08.log
>> MyLog.2008-09-08.1.log
>> MyLog.2008-09-08.2.log
>> ... etc.
>>
>> I started with log4cxx::RollingFileAppender, but it doesn't seem to
>> support FileName patterns.
>> Next, I tried log4cxx::rolling::RollingFileAppender with
>> TimeBasedRollingPolicy. This option does not allow rollover to be triggered
>> by file size.
>> Next, I tried log4cxx::rolling::RollingFileAppender with
>> TimeBasedRollingPolicy and SizeBasedTriggeringPolicy, but it seemed to
>> create a conflict because TimeBasedRollingPolicy also sets Triggering policy
>> for the appender.
>>
>> What is the solution I am looking for?
>>
>>  *Alex Rozenbaum*
>> Consultant
>>
>> *Thomson Reuters*
>>
>> Phone: 646-822-2821
>>
>> alex.rosenbaum@thomsonreuters.com
>> thomsonreuters.com
>>
>>
>> This email was sent to you by Thomson Reuters, the global news and
>> information company.
>> Any views expressed in this message are those of the individual sender,
>> except where the sender specifically states them to be the views of Thomson
>> Reuters.
>>
>
>
>
> --
> Dale King
>



-- 
Dale King

Re: TimeBased + SizeBased

Posted by Dale King <da...@gmail.com>.
You can't with log4cxx as it exists. You don't want TimeBasedRollingPolicy.
You want SizeBasedTriggeringPolicy with FixedWindowRollingPolicy. But
FixedWindowRollingPolicy only supports the index format specifier. If you
subclassed FixedWindowRollingPolicy  and overrode getFormatSpecifiers to be
something like this:

  PatternMap specs;
  RULES_PUT("i", IntegerPatternConverter);
  RULES_PUT("index", IntegerPatternConverter);
  RULES_PUT("d", FileDatePatternConverter);
  RULES_PUT("date", FileDatePatternConverter);
  return specs;

You could get close. I'll bet though it probably will not work completely
like you think it will. For instance it will only start a new log file when
the size is exceeded. So if there are few messages you could have the same
log file for weeks.

I think there is definitely some room for improvement in the area of
policies. For example, TimeBasedRollingPolicy cannot be used as a triggering
policy unless it is also the rolling policy. If you do, once it triggers it
will trigger for every message thereafter.

On Thu, Sep 25, 2008 at 3:54 PM, Alex Rosenbaum <
Alex.Rosenbaum@thomsonreuters.com> wrote:

>  I am trying to implement logging to rolling files. I want rollover to
> occur when the size reaches certain limit. At the same time I'd like file
> name to include date stamp, so the result looks like:
>
> MyLog.2008-09-08.log
> MyLog.2008-09-08.1.log
> MyLog.2008-09-08.2.log
> ... etc.
>
> I started with log4cxx::RollingFileAppender, but it doesn't seem to support
> FileName patterns.
> Next, I tried log4cxx::rolling::RollingFileAppender with
> TimeBasedRollingPolicy. This option does not allow rollover to be triggered
> by file size.
> Next, I tried log4cxx::rolling::RollingFileAppender with
> TimeBasedRollingPolicy and SizeBasedTriggeringPolicy, but it seemed to
> create a conflict because TimeBasedRollingPolicy also sets Triggering policy
> for the appender.
>
> What is the solution I am looking for?
>
>  *Alex Rozenbaum*
> Consultant
>
> *Thomson Reuters*
>
> Phone: 646-822-2821
>
> alex.rosenbaum@thomsonreuters.com
> thomsonreuters.com
>
>
> This email was sent to you by Thomson Reuters, the global news and
> information company.
> Any views expressed in this message are those of the individual sender,
> except where the sender specifically states them to be the views of Thomson
> Reuters.
>



-- 
Dale King