【问题标题】:CXF RS pretty HTTP request/response loggingCXF RS 漂亮的 HTTP 请求/响应日志记录
【发布时间】:2022-01-08 04:52:17
【问题描述】:

我正在努力设置漂亮的 HTPP 日志记录(用于请求和响应)

我正在使用 CXF REST API,并且正在使用 Spring Boot (https://cxf.apache.org/docs/springboot.html) 初始化 CXF。换句话说,我只是在定义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。

我不想使用 XML 配置,但我相信 XML 配置将是(基于 doc https://cxf.apache.org/docs/features.html):

    <cxf:bus>
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus>

如何以编程方式设置漂亮的日志记录?

【问题讨论】:

    标签: java spring-boot logging cxf cxfrs


    【解决方案1】:

    为了获得漂亮的日志记录,您需要执行以下操作:

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

    【讨论】:

      猜你喜欢
      • 2017-08-07
      • 1970-01-01
      • 2022-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多