You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Ron Grabowski <ro...@yahoo.com> on 2006/01/28 00:49:46 UTC

Re: Repeat ignores messages

Do you want to keep a count of every unique log message and append that
to the message?

Code:
log.Debug("A");
log.Debug("AB");
log.Debug("ABC");
log.Debug("ABCD");
log.Debug("A");
log.Debug("AB");
log.Debug("ABC");
log.Debug("ABCD");
log.Debug("A");
log.Debug("AB");
log.Debug("ABC");
log.Debug("ABCD");

Output:
A
AB
ABC
ABCD
A - repeated 2 times
AB - repeated 2 times
ABC - repeated 2 times
ABCD - repeated 2 times
A - repeated 3 times
AB - repeated 3 times
ABC - repeated 3 times
ABCD - repeated 3 times

Or do you want to queue up repeated lines and output them when the
repository shuts down?

A - repeated 3 times
AB - repeated 3 times
ABC - repeated 3 times
ABCD - repeated 3 times

If you queue up repeated outputs not only will they potential take up a
lot of memory, but you'd loose all of the time stamp information
associated with a logging event.

- Ron

--- Morten Andersen <mo...@vianett.no> wrote:


---------------------------------
  Hi all!

Can log4net ignore repeated log lines?

log.Debug("Hello world");
log.Debug("Hello world");
log.Debug("Hello world");
log.Debug("Hello world");
log.Debug("Another message");

The log lines above should result in something like this:

Hello world
Last message was repeated 3 times
Another message

-- 

Best Regards
Morten Andersen
Developer
Vianett AS | morten@vianett.no |+47 69 20 69 74 | Skype: mortander




Re: Repeat ignores messages

Posted by Morten Andersen <mo...@vianett.no>.

Stefan Bodewig wrote:
> On Sat, 28 Jan 2006, Ron Grabowski <ro...@yahoo.com> wrote:
>
>   
>> I understand how a simple counter variable could be used to keep
>> track of the number of repeated messages, but I still don't
>> understand where this log message will be generated:
>>
>>  Last message was repeated 2 times.
>>
>> When the timer inside the filter expires?
>>     
>
> Either that or when a different message gets logged.
>
> Stefan
>   
Yes, exactly!

Re: Repeat ignores messages

Posted by Stefan Bodewig <bo...@apache.org>.
On Sat, 28 Jan 2006, Ron Grabowski <ro...@yahoo.com> wrote:

> I understand how a simple counter variable could be used to keep
> track of the number of repeated messages, but I still don't
> understand where this log message will be generated:
> 
>  Last message was repeated 2 times.
> 
> When the timer inside the filter expires?

Either that or when a different message gets logged.

Stefan

Re: Repeat ignores messages

Posted by Ron Grabowski <ro...@yahoo.com>.
Here's a filter that ignores messages that contain the same exception
within a defined time period. For example if 500 identical log messages
are recieved within in 1 second time period only the first log message
is recorded:

http://tinyurl.com/cbq82
http://www.mail-archive.com/log4net-user%40logging.apache.org/msg02517.html

I understand how a simple counter variable could be used to keep track
of the number of repeated messages, but I still don't understand where
this log message will be generated:

 Last message was repeated 2 times.

When the timer inside the filter expires?

--- Morten Andersen <mo...@vianett.no> wrote:

> Your code was not generating any repeated lines. A repeated line is
> only 
> true if the last logged line on the appender is the same. There
> should 
> be no memory issues because it is just a checksum of the last logged 
> line, and two datetime variables that is stored. One datetime for the
> 
> first, and one that changes every time the line is repeated. When a 
> different checksum occurs the last checksum, and the two datetime
> values 
> is replaced.
> 
> There should also be a timeout value. In my example I have a 10
> second 
> timeout.
> 
> Code:
> log.Debug("Hello world");
> log.Debug("Hello world");
> log.Debug("Hello world");
> Thread.Sleep(10500);
> log.Debug("Hello world");
> 
> Output:
> Hello world
> Last message was repeated 2 times.
> Hello world
> 
> - Morten
> 
> Ron Grabowski wrote:
> > Do you want to keep a count of every unique log message and append
> that
> > to the message?
> >
> > Code:
> > log.Debug("A");
> > log.Debug("AB");
> > log.Debug("ABC");
> > log.Debug("ABCD");
> > log.Debug("A");
> > log.Debug("AB");
> > log.Debug("ABC");
> > log.Debug("ABCD");
> > log.Debug("A");
> > log.Debug("AB");
> > log.Debug("ABC");
> > log.Debug("ABCD");
> >
> > Output:
> > A
> > AB
> > ABC
> > ABCD
> > A - repeated 2 times
> > AB - repeated 2 times
> > ABC - repeated 2 times
> > ABCD - repeated 2 times
> > A - repeated 3 times
> > AB - repeated 3 times
> > ABC - repeated 3 times
> > ABCD - repeated 3 times
> >
> > Or do you want to queue up repeated lines and output them when the
> > repository shuts down?
> >
> > A - repeated 3 times
> > AB - repeated 3 times
> > ABC - repeated 3 times
> > ABCD - repeated 3 times
> >
> > If you queue up repeated outputs not only will they potential take
> up a
> > lot of memory, but you'd loose all of the time stamp information
> > associated with a logging event.
> >
> > - Ron
> >   
> 


Re: Repeat ignores messages

Posted by Morten Andersen <mo...@vianett.no>.
Your code was not generating any repeated lines. A repeated line is only 
true if the last logged line on the appender is the same. There should 
be no memory issues because it is just a checksum of the last logged 
line, and two datetime variables that is stored. One datetime for the 
first, and one that changes every time the line is repeated. When a 
different checksum occurs the last checksum, and the two datetime values 
is replaced.

There should also be a timeout value. In my example I have a 10 second 
timeout.

Code:
log.Debug("Hello world");
log.Debug("Hello world");
log.Debug("Hello world");
Thread.Sleep(10500);
log.Debug("Hello world");

Output:
Hello world
Last message was repeated 2 times.
Hello world

- Morten

Ron Grabowski wrote:
> Do you want to keep a count of every unique log message and append that
> to the message?
>
> Code:
> log.Debug("A");
> log.Debug("AB");
> log.Debug("ABC");
> log.Debug("ABCD");
> log.Debug("A");
> log.Debug("AB");
> log.Debug("ABC");
> log.Debug("ABCD");
> log.Debug("A");
> log.Debug("AB");
> log.Debug("ABC");
> log.Debug("ABCD");
>
> Output:
> A
> AB
> ABC
> ABCD
> A - repeated 2 times
> AB - repeated 2 times
> ABC - repeated 2 times
> ABCD - repeated 2 times
> A - repeated 3 times
> AB - repeated 3 times
> ABC - repeated 3 times
> ABCD - repeated 3 times
>
> Or do you want to queue up repeated lines and output them when the
> repository shuts down?
>
> A - repeated 3 times
> AB - repeated 3 times
> ABC - repeated 3 times
> ABCD - repeated 3 times
>
> If you queue up repeated outputs not only will they potential take up a
> lot of memory, but you'd loose all of the time stamp information
> associated with a logging event.
>
> - Ron
>   

Re: Repeat ignores messages

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 27 Jan 2006, Ron Grabowski <ro...@yahoo.com> wrote:

> Do you want to keep a count of every unique log message and append
> that to the message?

I guess, neither of both.  It is a handy feture of some logging
packages (Linux version of syslog for example) to batch up consecutive
unique messages.  In your example

> Code:
> log.Debug("A");
> log.Debug("AB");
> log.Debug("ABC");
> log.Debug("ABCD");
> log.Debug("A");
> log.Debug("AB");
> log.Debug("ABC");
> log.Debug("ABCD");
> log.Debug("A");
> log.Debug("AB");
> log.Debug("ABC");
> log.Debug("ABCD");

The output would be exactly the same with and without batching, but 

log.Debug("A");
log.Debug("AB");
log.Debug("ABC");
log.Debug("ABCD");
log.Debug("A");
log.Debug("A");
log.Debug("A");
log.Debug("AB");

would lead to 

A
AB
ABC
ABCD
A
last message repeated two times
AB

If you want to get fancy you'd make that "twice" instead of "two
times".

I've once done something similar for an in-house (Java) logging
framework in a past job.  The way I implemented it would translate
into an appender that was a decorator around another appender which
just keeps track of the last message it logged, the memory overhead is
minimal.  In addition I had a thread that made sure log statements
were not delayed, so if the last AB log never happened a trigger would
cause the "last message repeated two times" after some time.

Stefan