logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Error while logging , using DbAppender
Date Fri, 19 Jun 2015 23:30:02 GMT
Hi Mohan,

You should know that Log4j 1 is not supported or maintained ATM. We are all
actively supporting and developing Log4j 2 though. I would use v2.x if you
can...

Gary

On Fri, Jun 19, 2015 at 1:51 PM, Mohan Bhargava <mohanbola@gmail.com> wrote:

> 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
>       FOR EACH ROW
>     DECLARE
>     BEGIN
>        SELECT logging_event_id_seq.nextval
>        INTO :new.event_id FROM dual;
>        new:sequence_number := :new.event_id;
>     END;
>
>
>     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"
>     xmlns:log4j='http://jakarta.apache.org/log4j/'>
>
>     <root>
>     <level value="ALL" />
>     <appender-ref ref="DB" />
>     </root>
>
>     <appender name="DB" class="org.apache.log4j.DBAppender">
>     <param name="locationInfo" value="true" />
>     <connectionSource
>     class="org.apache.log4j.receivers.db.DriverManagerConnectionSource">
>     <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" />
>     </connectionSource>
>     </appender>
>
>     </log4j:configuration>
>
> 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();
>     logObj.logMessage();
>     }
>     }
>
> 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
>
> "(renderer*,throwableRenderer?,appender*,plugin*,(category|logger)*,root?,(categoryFactory|loggerFactory)?)".
>     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
> [oracle.jdbc.driver.OracleDriver].
>     log4j: Setting property [url] to [jdbc:oracle:thin:@//
> some.server.name:1501/some.databse.name].
>     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
>
> oracle.jdbc.driver.T4CVarcharAccessor.StringToNUMBER(T4CVarcharAccessor.java:832)
>     at
>
> oracle.jdbc.driver.T4CVarcharAccessor.getNUMBER(T4CVarcharAccessor.java:239)
>     at
> oracle.jdbc.driver.T4CVarcharAccessor.getInt(T4CVarcharAccessor.java:527)
>     at
> oracle.jdbc.driver.GeneratedStatement.getInt(GeneratedStatement.java:217)
>     at
>
> oracle.jdbc.driver.GeneratedScrollableResultSet.getInt(GeneratedScrollableResultSet.java:573)
>     at org.apache.log4j.DBAppender.append(DBAppender.java:281)
>     at
> org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
>     at
>
> org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
>     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)
>     at
>
> oracle.jdbc.driver.T4CVarcharAccessor.StringToNUMBER(T4CVarcharAccessor.java:825)
>     ... 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
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

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