Bug 40889 - repeated entries in log after failure
Summary: repeated entries in log after failure
Status: NEEDINFO
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-03 07:51 UTC by Jack Kustanowitz
Modified: 2008-08-02 12:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Kustanowitz 2006-11-03 07:51:34 UTC
I found that after a failed log entry (JdbcAppender) in mysql (I believe 5.0 
but I'm not sure), mysql does in fact write the entry, but an error must be 
returned at some point because it's not removed from the buffer.

This happened after writing non-ascii characters to the field, or after 
exceeding the 255 character limit I had set on the field.

I fixed this by moving "removes.add(logEvent);" to be BEFORE the execute(sql); 
statement, which ensures it will always get removed, even if an error occurs.

Since this is not necessarily the desired behavior for all apps, I would 
recommend exposing this as a setting on the class, controlled via some 
variable like "removeFromBufferOnError" or something more creative.

This is my first posting to a jakarta project -- thanks for all the hard work 
that makes our lives easier!
Comment 1 Henri Yandell 2006-12-21 13:56:18 UTC
I'm not a log4j developer, but happened to be looking at this at work.

It seems to me that chiefly MySQL is at fault here if it is indeed throwing an
error and yet still writing it to the db. 

It seems that log4j could solve this by changing the execute() method to be in
charge of adding to the removes.add(..) call, and then having a setAutoCommit in
there so that a rollback is performed if an Exception is thrown (and the
removes.add(...) is not done). This change of responsibility might be bad for
subclasses; so the other option would be to change execute() to take a
Connection parameter and put flushBuffer() in charge of the Connection.
Comment 2 Thorbjørn Ravn Andersen 2008-08-02 12:06:17 UTC
Please provide sample code demonstrating the behaviour described.