Logging Feature

Stable • Since 0.14.0

Allows logging HTTP headers and bodies of SOAP requests and responses for both CXF clients and services.

Maven coordinates

Create a new project using quarkus-cxf-rt-features-logging on code.quarkus.io or add these coordinates to your existing project:

<dependency>
    <groupId>io.quarkiverse.cxf</groupId>
    <artifactId>quarkus-cxf-rt-features-logging</artifactId>
</dependency>
Check the User guide and especially its Dependency management section for more information about writing applications with CXF Extensions for Quarkus.

Usage

This extension wraps the CXF org.apache.cxf:cxf-rt-features-logging artifact thus providing the org.apache.cxf.ext.logging.LoggingFeature class.

LoggingFeature instances can be configured per service or per client. You can either use a LoggingFeature instance with default settings or you can produce a custom LoggingFeature CDI bean.

Attaching LoggingFeature to a client or service

You have two options to do that:

  1. In application.properties:

    # For a service:
    quarkus.cxf.endpoint."/hello".features=org.apache.cxf.ext.logging.LoggingFeature
    # For a client:
    quarkus.cxf.client."myClient".features=org.apache.cxf.ext.logging.LoggingFeature
    There is an example in Your first SOAP Web service chapter of the User guide.

    or alternatively

  2. Use the @Features annotation of CXF:

    @org.apache.cxf.feature.Features (features = {"org.apache.cxf.ext.logging.LoggingFeature"})
    @WebService(endpointInterface = "org.acme.SayHi", targetNamespace = "uri:org.acme")
    public class SayHiImplementation implements SayHi {
       public long sayHi(long arg) {
           return arg;
       }
       //...
    }

Custom LoggingFeature

LoggingFeature offers some attributes that may be worth customizing in some situations.

E.g. if your payloads are complex, you may want to set prettyLogging to true to render them with an indentation. Or if your messages are big and you need to see them complete in the log, you may want to increase the limit.

Check the CXF message logging page for all possible LoggingFeature attributes.

To achieve this, you can produce a custom LoggingFeature bean that is then picked by Quarkus CXF for clients and services where you specified *.features = org.apache.cxf.ext.logging.LoggingFeature:

import org.apache.cxf.ext.logging.LoggingFeature;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;

class Producers {

    @Produces
    @ApplicationScoped
    LoggingFeature loggingFeature() {
        LoggingFeature loggingFeature = new LoggingFeature();
        loggingFeature.setPrettyLogging(true);
        loggingFeature.setLimit(Integer.MAX_VALUE);
        return loggingFeature;
    }
}

Multiple custom LoggingFeatures

In case you’d like to configure the LoggingFeatures for your individual services or clients differently, you can so that by defining multiple @Named LoggingFeature beans:

import org.apache.cxf.ext.logging.LoggingFeature;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;

class Producers {

    @Produces
    @ApplicationScoped
    @Named("limitedLoggingFeature") // "limitedLoggingFeature" is redundant if the name of the method is the same
    LoggingFeature limitedLoggingFeature() {
        LoggingFeature loggingFeature = new LoggingFeature();
        loggingFeature.setLimit(Integer.MAX_VALUE);
        return loggingFeature;
    }

    @Produces
    @ApplicationScoped
    @Named("prettyLoggingFeature")
    LoggingFeature prettyLoggingFeature() {
        LoggingFeature loggingFeature = new LoggingFeature();
        loggingFeature.setPrettyLogging(true);
        return loggingFeature;
    }
}

and then refer to them by their names prefixed with # in application.properties:

# For a service:
quarkus.cxf.endpoint."/hello".features = #limitedLoggingFeature
# For a client:
quarkus.cxf.client."myClient".features = #prettyLoggingFeature
Please note that named Feature beans are currently not supported for SOAP clients.

Configuration

The logging feature can be associated with a SOAP client or service using the following configuration properties: