logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Merin Shaji" <merinsh...@gmail.com>
Subject Re: JDBC Appender
Date Tue, 22 Aug 2006 06:38:42 GMT
Jake,

Thanks for your reply. I tried out NDC and is working fine.

But I could not use MDC. It gave the following error:

java.lang.NoSuchMethodError: org.apache.log4j.spi.LoggingEvent.getMDC
(Ljava/lang/String;)Ljava/lang/Object;

I am using log4j-1.3alpha0.jar and a jdbcappender which extends log4j (
org.apache.log4j.jdbcplus)

My code snippet is:

*Logger loggerObj = LoggerFactory.getLogger("UsageLogger");*

*NDC.push(sessionUser);*

*MDC.put("LogUrl",url);*

*loggerObj.info("MDC test");*

*NDC.pop();*

*MDC.remove("LogUrl");*

My log4j.xml entry is:

*<param **name="sql" value="INSERT INTO LOGSTAB (id, prio, cat, thread, msg,
throwable, ndc, mdc, the_timestamp) VALUES (FELIXLOGS_SEQ.NEXTVAL,@INC@,
'@PRIO@', '@CAT@', '@THREAD@', '@MSG@', '@THROWABLE@', '@NDC@',
'@MDC:LogUrl@', CURRENT_TIMESTAMP)"** />*

Why is it happening? I understand that you can store only one value in the
database using NDC. Please correct me if I am wrong.

Thanks & Regards

Merin


On 8/21/06, Jacob Kjome <hoju@visi.com> wrote:
>
>
> If you want to use MDC or NDC, you will have to register the values using
> your
> classes.  However, once you have that, you can redefine the layout of your
> appender in the config file without changing your classes.  This article
> provides both an example of a JDBCAppender configuration and talks about
> MDC
> and NDC.  They are discussed separately, but you can extrapolate on how
> you
> would add the MDC/NDC values in your layout...
>
> http://www.onjava.com/pub/a/onjava/2002/08/07/log4j.html?page=3
>
>
> Jake

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