the corner office

a blog, by Colin Pretorius

CXF, log4j, silly mistakes

If you were using CXF, and wanted all the logging output to be handled by log4j, you'll probably have Googled for an answer and come across this excellent post which explains how to configure CXF to use log4j. And you might duly create the necessary file in src/main/webapp/META-INF or the like and then spent a lot of time debugging CXF's LogUtils class trying to figure out why it isn't picking up your config change.

Only then might you realise that the post in question is indeed correct, and explains exactly what you need to do: put the string org.apache.cxf.common.logging.Log4jLogger into a file named META-INF/cxf/org.apache.cxf.Logger in the classpath. In the classpath. And then you'll go doh! Muppet! A web app's META-INF directory isn't in the classpath, and your mind is making a connection which isn't there. You should be putting the file into src/main/resources directory, or whereever else in your classpath. Classpath dammit, classpath. And you might feel embarassed at having made this silly mistake, but you'd only be human. And I think Donald Norman would be on your side.

{2008.05.01 22:54}

Comments:

1. nj (2008.12.11 - 13:20) #

still not clear! do i create a directory META-INF->cxf and create a file named org.apache.cxf.Logger in it with that line? it gives NoClassDef error if i do that! Sorry for being so dumb!

2. Colin (2008.12.11 - 15:10) #

It sounds like you're doing the right thing, I'm not sure why you'd be getting a NoClassDefFound error though. What you can do is put a debug breakpoint in cxf's LogUtils class, iirc there's a static block which has the logic that looks for this file. That may give you some pointers.

3. Björn Þór Jónsson (2010.03.16 - 14:32) #

Thanks! That was the missing link. And yes, I did go duh! :)

« Ken v Boris

» SpringSource Application Platform