簡體   English   中英

CXF RS 漂亮 HTTP 請求/響應日志記錄

[英]CXF RS pretty HTTP request/response logging

我正在努力設置漂亮的 HTPP 日志記錄(用於請求和響應)

I am using CXF REST API and I am initializing CXF using Spring Boot ( https://cxf.apache.org/docs/springboot.html ). 換句話說,我只是在定義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

並且自動我有功能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>

如何以編程方式設置漂亮的日志記錄?

為了獲得漂亮的日志記錄,您需要執行以下操作:

@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 {}");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM