logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Milind Rao" <mili...@bellsouth.net>
Subject Problems with JDBCAppender
Date Wed, 06 Aug 2003 09:52:47 GMT
I created a subclass of JDBCAppender for logging to the database and am running into the following
problems.  I'd 
apreciate if someone who's been using this can shed some light on them.

1. Unless the Buffer Size is 1 (or less than the number of logs being written), the logs don't
make it to the database.  The 
"getLogStatement" method is never called.

2. This problem may be related to the buffer size problem above. but if I set the buffer size
to say 2 and create one log 
and exit the program, the finalize method of JDBCAppender doesn't get called and the logs
don't get flushed to the 
database.

3. There should be a "commit" parameter for the JDBCAppender.  Incidentally there is a related
bug somewhere that I 
haven't had the time to track down.  If I don't set "AutoCommit" to "true" on the connection,
prior to returning it from the 
"getConnection" method, the database hangs while accesing the Log table.  This is with DB2.
 I don't know exactly where 
the problem lies.  But since I did want to set AutoCommit to true, I didn't spend the time
following up.

4. In my data access classes, I normally set AutoCommit to false and do my own commits after
successful completion of 
the SQL call.  In case of an exception, I do a rollback.  If I don't do a rollback on error,
then the next (unrelated) 
successful call to the database commits the earlier failed SQL.  Doesn't one need to do a
rollback when auto commit is 
set to true?  If not, then it's missing in JDBCAppender's execute method.  I'm thinking of
just redefining the "execute" 
method instead of the "getConnection" and "closeConnection" methods.

5. If the appender I use in the fallback error handler is also used by the "root" logger,
then 
an "arrayIndexOutOfBoundsException" exception is thrown while accesing the 
"appenderList" in the "appendLoopOnAppenders" method of "AppenderAttachableImpl".  ie. if
the error handler for 
JDBCAppender is "Console" and "Console" is also used as an appender in root, then this exception
is thrown when the 
fallback appender is used.  
As an aside, the documentation is really bad.  It took me ages to find that I had to use "<root-ref/>"
to set the root logger 
as the fallback appender.  I really think we should move to a schema based XML configuration
rather than a DTD based.

6. If I have 2 appenders in root, an exception is thrown while writing to the database and
the fallback handler is called, 
the first log doesn't show up in the second appender in root.  In my configuration file below,
the first log shows up in the 
file (fallback of database appender) but doesn't show up on the console.  If the appenders
are reversed, then it doesn't 
show up in the file, but shows up on the console.  This happens only with the log that was
being written to the database 
when the exception occurred.  The remaining logs show up fine in both appenders.


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Database Appender -->
    <appender name="BSDBAppender" class="brickstream.logging.model.BSDBAppender">
        <!-- fallback on error -->
        <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
            <root-ref/>
            <appender-ref ref="BSFileAppender"/>
        </errorHandler>
        <param name = "BufferSize" value ="1"/>
    </appender>

    <!-- Secondary File Appender -->
    <appender name="BSFileAppender" class="brickstream.logging.model.BSFileAppender">
        <param name = "LogFileSuffix" value =".log"/>
        <layout class="brickstream.logging.model.BSLayout"/>
    </appender>

    <!-- Console Appender -->
    <appender name="Console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
              value="[%-5p] %m %n"
            />
        </layout>
    </appender>

    <root>
        <level value="debug"/>
        <appender-ref ref="BSDBAppender"/>
        <appender-ref ref="Console"/>
    </root>

</log4j:configuration>



Regards
Milind



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


Mime
View raw message