logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohan Bhargava <mohanb...@gmail.com>
Subject Fwd: Error while logging , using DbAppender
Date Fri, 19 Jun 2015 20:51:03 GMT
I am trying to log to Oracle 11g database using log4j's `DBAppender ( part
of Apache Extras project for log4j ) . I am using log4j-1.2.17

Have created the required tables by modifying the Oracle.sql script. Had to
tweak logging_event_id_seq_trig trigger to populate event_id column in
`logging_event` table. This was to avoid SQLException , resulting out of
null values in event_id column.

    CREATE SEQUENCE logging_event_id_seq MINVALUE 1 START WITH 1;

    CREATE TABLE logging_event
        sequence_number   NUMBER(20) NOT NULL,
        timestamp         NUMBER(20) NOT NULL,
        rendered_message  VARCHAR2(4000) NOT NULL,
        logger_name       VARCHAR2(254) NOT NULL,
        level_string      VARCHAR2(254) NOT NULL,
        ndc               VARCHAR2(4000),
        thread_name       VARCHAR2(254),
        reference_flag    NUMBER(5),
        caller_filename   VARCHAR2(254) NOT NULL,
        caller_class      VARCHAR2(254) NOT NULL,
        caller_method     VARCHAR2(254) NOT NULL,
        caller_line       CHAR(4) NOT NULL,
        event_id          NUMBER(10) PRIMARY KEY

    CREATE TRIGGER logging_event_id_seq_trig
      BEFORE INSERT ON logging_event
       SELECT logging_event_id_seq.nextval
       INTO :new.event_id FROM dual;
       new:sequence_number := :new.event_id;

    CREATE TABLE logging_event_property
        event_id      NUMBER(10) NOT NULL,
        mapped_key        VARCHAR2(254) NOT NULL,
        mapped_value      VARCHAR2(1024),
        PRIMARY KEY(event_id, mapped_key),
        FOREIGN KEY (event_id) REFERENCES logging_event(event_id)

    CREATE TABLE logging_event_exception
        event_id         NUMBER(10) NOT NULL,
        i                NUMBER(5)  NOT NULL,
        trace_line       VARCHAR2(254) NOT NULL,
        PRIMARY KEY(event_id, i),
        FOREIGN KEY (event_id) REFERENCES logging_event(event_id)

I am logging to the database using Oracle JDBC Driver Manager.Here is what
my log4j.xml looks like

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

    <level value="ALL" />
    <appender-ref ref="DB" />

    <appender name="DB" class="org.apache.log4j.DBAppender">
    <param name="locationInfo" value="true" />
    <param name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
    <param name="url"
    value="jdbc:oracle:thin:@//some.server.name:1501/some.databse.name" />
    <param name="user" value="some_user" />
    <param name="password" value="some_pwd" />


I have written a simple java program to test logging:

    import org.apache.log4j.Logger;

    public class LoggingTest
    public static Logger log;

    public void logMessage()
    log = Logger.getLogger(LoggingTest.class.getName());

    log.info("Entered the logMessage method");
    log.debug("This is a DEBUG message \n");
    log.error("This is a ERROR message \n");
    log.fatal("This is a FATAL message \n");
    log.info("This is a INFO message \n");
    log.warn("This is a WARNING message \n");

    public static void main(String[] args)
    LoggingTest logObj = new LoggingTest();

I am getting the following error (for every log statement) when I run log4j
in debug mode.  Whats puzzling is despite the error , I still see events
being logged to the table. I cant figure out what is causing this
particular error.

    log4j:WARN Continuable parsing error 23 and column 23
    log4j:WARN The content of element type "log4j:configuration" must match
    log4j: reset attribute= "false".
    log4j: Threshold ="null".
    log4j: Level value for root is  [ALL].
    log4j: root level set to ALL
    log4j: Class name: [org.apache.log4j.DBAppender]
    log4j: Setting property [locationInfo] to [true].
    log4j: Setting property [driverClass] to
    log4j: Setting property [url] to [jdbc:oracle:thin:@//
    log4j: Setting property [user] to [some_user].
    log4j: Setting property [password] to [some_pwd].
    log4j: setConnectionSource called for DBAppender
    log4j: DBAppender.activateOptions called
    log4j: Adding appender named [DB] to category [root].
    log4j:ERROR problem appending event
    java.sql.SQLException: Invalid conversion requested
    at org.apache.log4j.DBAppender.append(DBAppender.java:281)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.info(Category.java:666)
    at com.log.test.LoggingTest.logMessage(LoggingTest.java:15)
    at com.log.test.LoggingTest.main(LoggingTest.java:28)
    Caused by: java.lang.NumberFormatException
    at java.math.BigDecimal.<init>(BigDecimal.java:470)
    at java.math.BigDecimal.<init>(BigDecimal.java:739)
    ... 12 more

On setting breakpoints i see the exception being thrown where a string is
being converted to big decimal. this code expects an exponent , when it
does not find one its throws an exception

                // exponent expected
                if ((c != 'e') && (c != 'E'))
                    throw new NumberFormatException();

Can someone please help me understand the cause of this error and suggest a
fix for it

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message