Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Since CXF 3.1 the message logging code was moved into a separate module and gathered some new features.

  • Auto logging for existing CXF endpoints and clients
  • Uses slf4j MDC to log meta data separately
  • Adds meta data for Rest calls
  • Adds MD5 message id and exchange id for correlation
  • Simple interface for writing your own appenders

Manual Usage

Code Block
languagexml
titleCXF LoggingFeature
    <jaxws:endpoint ...>
      <jaxws:features>
       <bean class="org.apache.cxf.ext.logging.LoggingFeature"/>
      </jaxws:features>
    </jaxws:endpoint>

The LoggingFeature can be used with JAXWS as well JAXRS Endpoints and Clients. It can also be specified using the @Features annotation. The feature should be used instead of adding the LoggingIn/OutInterceptors manually.

Properties

The following properties can be set on the LoggingFeature:

PropertyExplanation
limitThe size limit at which messages are truncated in the log. The default is 48 * 1024.
inMemThreshold

Size limit when messages are written to disk. The default is -1, which means do not write to disk.

prettyLoggingFor XML content, turn on pretty printing in the logs. The default is false.
logBinaryLog binary payloads by default. The default is false.
logMultipartLog multipart payloads by default. The default is true.


Slf4j MDC values for meta data

This is the raw logging information you get for a SOAP call:

FieldValue
@timestamp2015-06-08T14:43:27,097Z
MDC.addresshttp://localhost:8181/cxf/personService
MDC.bundle.id90
MDC.bundle.nameorg.apache.cxf.cxf-rt-features-logging
MDC.bundle.version3.1.0
MDC.content-typetext/xml; charset=UTF-8
MDC.encodingUTF-8
MDC.exchangeId56b037e3-d254-4fe5-8723-f442835fa128
MDC.headers{content-type=text/xml; charset=UTF-8, connection=keep-alive, Host=localhost:8181, Content-Length=251, SOAPAction="", User-Agent=Apache CXF 3.1.0, Accept=*/*, Pragma=no-cache, Cache-Control=no-cache}
MDC.httpMethodPOST
MDC.messageIda46eebd2-60af-4975-ba42-8b8205ac884c
MDC.portNamePersonServiceImplPort
MDC.portTypeNamePersonService
MDC.serviceNamePersonServiceImplService
MDC.typeREQ_IN
levelINFO
loc.classorg.apache.cxf.ext.logging.slf4j.Slf4jEventSender
loc.fileSlf4jEventSender.java
loc.line55
loc.methodsend
loggerClassorg.ops4j.pax.logging.slf4j.Slf4jLogger
loggerNameorg.apache.cxf.services.PersonService.REQ_IN
message<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getAll xmlns:ns2="http://model.personservice.cxf.karaf.tutorial.lr.net/"; xmlns:ns3="http://person.jms2rest.camel.karaf.tutorial.lr.net"/></soap:Body></soap:Envelope>;
threadNameqtp80604361-78
timeStamp1433774607097


A lot of the details are in the MDC values which are by default normally not displayed in the log file. You need to change your pax logging config to make these visible.ogged or log some services to another file.

Enablling / disabling logging by changing the logger config

The logger name is "<service namespace>.<ServiceName>.<type>". In the karaf log file it by default only shows the type but you can change this.

You can use the logger name to fine tune which services you want to log this way. For example set the debug level to WARN for noisy services to avoid that they are logged.

Message id and exchange id

The messageId allows to uniquely identify messages even if they were collected from several servers. It is also transported over the wire so a request sent on one machine can be correlated with the request received on another machine.

The exchangeId will be the same for an incoming request and the response sent out or on the other side for an outgoing request and the response for it. This allows to correlate request and responses and so follow the conversations.

Simple interface to write custom appenders

Write a custom LogEventSender and set it on the LoggingFeature to do custom logging. All meta data can be accessed from the class LogEvent.

...

By default, the Slf4jEventSender logs messages a at "INFO" level. From CXF 3.3.3, it is possible to easily change this by setting a log level on Slf4jEventSender and wiring it into the LoggingFeature. For example:

...