Configuring CXF Logging To Go Through Log4J

Apparently, CXF has chosen the JSE logging API as their API against logging. But you can make CXF log through Log4J quite easily. In the org.apache.cxf.common.logging package of the CXF apidocs, I found the Log4JLogger class, which is a specialization of the JSE logging api java.util.logging.Logger class, delegating logging to a Log4J implementation.

Configuring Log4J in CXF

In the same package as Log4JLogger, I also found the LogUtils class, which CXF uses to obtain logger instances from. This class also contains a static final string KEY, which is set to the value org.apache.cxf.Logger. CXF uses this value, to bootstrap which logging API to use.

You can either put a META-INF/cxf/org.apache.cxf.Logger file onto the classpath with the org.apache.cxf.common.logging.Log4jLogger class name in it as a single line, or you can supply a -Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger system property to your code, when executing.

January 30, 2008  Tags: , , ,   Posted in: Programming

5 Responses

  1. Tech Per » Blog Archive » Viewing Inbound and Outbound Messages in CXF - January 30, 2008

    [...] messages through its logging API. As a standard, the logging API in CXF is JDK logging, but you can configure CXF to use Log4J logging instead. You will need to ensure, that at least INFO level logging has been enabled for these [...]

  2. Tech Per » Blog Archive » Making CXF Log RuntimeExceptions From Server Implementations - February 28, 2008

    [...] mentioned in my post on how to configure log4j as logging engine in cxf, cxf comes out of the box with JavaSE logging (java.util.logging) as its logging engine. If you [...]

  3. Norm - November 12, 2008

    I can’t find META-INF/cxf/org.apache.cxf.Logger file in my CXF directory.

    Any idea how can I achieve logging.

  4. polesen - November 12, 2008

    That is because you are supposed to supply that file yourself, instead of relying on the default.

    Create the META-INF/cxf/org.apache.cxf.Logger file somewhere on your classpath. If you are building a war, for instance, it should end up in WEB-INF/classes/META-INF/cxf/org.apache.cxf.Logger (or inside a jar in WEB-INF/lib).

  5. satheesh - March 11, 2010

    Really gr8! helped me to solve longing issues in CXF
    I have created META-INF/cxf/org.apache.cxf.Logger file under WEB-INF/classes directory.
    Satheesh

Leave a Reply