[logback-user] No context given for compiler/Parser Error with SimpleMDC example

Daniel King dking at vurv.com
Fri Apr 11 21:33:17 CEST 2008


Any help would be greatly appreciated since I want my company to change
over from log4j to slf4j and logback.  However with this error, I won't
be able to change over to logback only slf4j.  I searched the archives
and found no bug or solution for this error:

 

LOGBACK: No context given for
ch.qos.logback.core.pattern.parser.Compiler at 4a65e0

15:10:23.205 [main] INFO  chapter7.SimpleMDC - Check enclosed.

%PARSER_ERROR_X %PARSER_ERROR_X -
%PARSER_ERROR_m%PARSER_ERROR_n15:10:23.220 [main] DEBUG
chapter7.SimpleMDC - The most beautiful two words in English.

%PARSER_ERROR_X %PARSER_ERROR_X -
%PARSER_ERROR_m%PARSER_ERROR_n15:10:23.220 [main] INFO
chapter7.SimpleMDC - I am not a crook.

%PARSER_ERROR_X %PARSER_ERROR_X -
%PARSER_ERROR_m%PARSER_ERROR_n15:10:23.220 [main] INFO
chapter7.SimpleMDC - Attributed to the former US president. 17 Nov 1973.

%PARSER_ERROR_X %PARSER_ERROR_X - %PARSER_ERROR_m%PARSER_ERROR_n

 

I'm using the following:

 

Windows XP

JDK 1.6

 

I created a directory named logback.

 

I put the following jars in it:

 

logback-core-0.9.9.jar

logback-classic-0.9.9.jar

logback-examples-0.9.9.jar

slf4j-api-1.5.0.jar  (I also tried slf4j-api-1.4.3.jar with same
results)

 

I created a bat file named SimpleMDC.bat.  It contains the following:

 

java -classpath
"slf4j-api-1.5.0.jar;logback-core-0.9.9.jar;logback-classic-0.9.9.jar;lo
gback-examples-0.9.9.jar;" chapter7.SimpleMDC

 

I opened a command prompt and ran the bat file with the following
output:

 

C:\logback>SimpleMDC

 

C:\logback>java -classpath
"slf4j-api-1.5.0.jar;logback-core-0.9.9.jar;logback-classic-0.9.9.jar;lo
gback-examples-0.9.9.jar;" chapter7.SimpleMDC

LOGBACK: No context given for
ch.qos.logback.core.pattern.parser.Compiler at 4a65e0

15:10:23.205 [main] INFO  chapter7.SimpleMDC - Check enclosed.

%PARSER_ERROR_X %PARSER_ERROR_X -
%PARSER_ERROR_m%PARSER_ERROR_n15:10:23.220 [main] DEBUG
chapter7.SimpleMDC - The most beautiful two words in English.

%PARSER_ERROR_X %PARSER_ERROR_X -
%PARSER_ERROR_m%PARSER_ERROR_n15:10:23.220 [main] INFO
chapter7.SimpleMDC - I am not a crook.

%PARSER_ERROR_X %PARSER_ERROR_X -
%PARSER_ERROR_m%PARSER_ERROR_n15:10:23.220 [main] INFO
chapter7.SimpleMDC - Attributed to the former US president. 17 Nov 1973.

%PARSER_ERROR_X %PARSER_ERROR_X - %PARSER_ERROR_m%PARSER_ERROR_n

 

It might be of interest that whenever I used 0.8.1, 0.9.1, 0.9.2, 0.9.3,
0.9.4, 0.9.5, 0.9.6 and 0.9.7 core and classic jars I got the following
error when running the SimpleMDC code in a Maven 2 project using Eclipse
3.3 I created:

 

SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".

SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for
further details.

Exception in thread "main" java.lang.NoClassDefFoundError:
org/slf4j/impl/StaticMDCBinder

      at org.slf4j.MDC.<clinit>(MDC.java:69)

      at com.vurv.logging.MDCLogging.main(MDCLogging.java:15)

 

However, whenever I used 0.9.8 and 0.9.9 core and classic jars I got the
same parser_error as listed above.

 

Also the Ch# 7 example in the docs is missing this line of code: import
ch.qos.logback.classic.spi.LoggingEvent;

 

It is in the SimpleMDC code in the examples jar though.

 

I also took this same project and copied it.  Then I changed it over to
use slf and log4j.  I changed the logback code to log4j like this:

 

Replace this code:

            // Configure logback

            PatternLayout layout = new PatternLayout();

            layout.setPattern("%X{first} %X{last} - %m%n");

            layout.start();

            ConsoleAppender<LoggingEvent> appender = new
ConsoleAppender<LoggingEvent>();

            appender.setLayout(layout);

            appender.start();

 

            // cast root logger to c.q.logback.classic.Logger so that we
can attach an

            // appender to it

            ch.qos.logback.classic.Logger root =
(ch.qos.logback.classic.Logger) LoggerFactory.getLogger("root");

            root.addAppender(appender);

 

With this code:

 

            PatternLayout layout = new PatternLayout();

            layout.setConversionPattern("%X{first} %X{last} - %m%n");

            ConsoleAppender appender = new ConsoleAppender(layout);

            BasicConfigurator.configure(appender);

 

The rest of the code is identical.  This produced the correct output
with slf4j and log4j.

 

Dorothy Parker - Check enclosed.

Dorothy Parker - The most beautiful two words in English.

Richard Nixon - I am not a crook.

Richard Nixon - Attributed to the former US president. 17 Nov 1973.

 

Thanks,

Daniel


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://qos.ch/pipermail/logback-user/attachments/20080411/83f10a81/attachment.htm 


More information about the Logback-user mailing list