Reputation: 1029
I am struggling to set up pretty HTPP logging (for requests and responses)
I am using CXF REST API and I am initializing CXF using Spring Boot (https://cxf.apache.org/docs/springboot.html). In other words I am just defining application.properties
server.port=8443
server.servlet.contextPath=/api/
cxf.path=/cxf
cxf.jaxrs.classes-scan=true
cxf.jaxrs.classes-scan-packages=com.mycomp \
,io.swagger.v3.jaxrs2.integration.resources \
,com.fasterxml.jackson
and automagically I have functional REST API.
I do not want to use XML configuration, but I believe, that XML config would be (based on doc https://cxf.apache.org/docs/features.html):
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
How can I set up pretty logging programmatically ?
Upvotes: 1
Views: 700
Reputation: 1029
In order to have pretty logging you need to do following:
@Configuration
/**
* Configure CXF http requests for pretty logging
*/
public class CxfLoggingConfig {
private static final Logger log = LoggerFactory.getLogger(CxfLoggingConfig.class);
@Autowired
private Bus bus;
@PostConstruct
private void init() {
log.debug("Initialising CxfLoggingConfig");
LoggingFeature loggingFeature = new LoggingFeature();
loggingFeature.setPrettyLogging(true);
loggingFeature.setVerbose(true);
//loggingFeature.setLogMultipart(true);
bus.getFeatures().add(loggingFeature);
log.debug("CxfLoggingConfig initialised by {}");
}
}
Upvotes: 1