骆驼码头组件日志记录
问题描述:
我该如何在骆驼中启用http日志?我正在使用rest-dsl。我想看到的HTTP标题和正文为每个请求和响应我的代码:骆驼码头组件日志记录
restConfiguration()
.component("jetty")
.host("0.0.0.0")
.port(port)
.scheme("https")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES")
.dataFormatProperty("json.in.enableFeatures", "FAIL_ON_NULL_FOR_PRIMITIVES")
.componentProperty("sslKeyPassword", KEYSTORE_PASSWORD)
.componentProperty("sslKeystore", KEYSTORE)
.componentProperty("sslPassword", KEYSTORE_PASSWORD)
.enableCORS(true)
.componentProperty("traceEnabled", "true")
// swagger
.apiContextPath("api-doc")
.apiProperty("api.title", "Mobile Api").apiProperty("api.version", "v1.0")
.apiProperty("schemes", "https")
;
和
rest(MOBILE_API_PATH).produces("application/json").consumes("application/json")
.post("/transaction").type(MobileTransactionRequest.class).outType(MobileTransactionResponse.class)
.to("direct:mobileTransaction")
答
要启用日志记录组件,您需要创建这个豆:
<bean id="log" class="org.eclipse.jetty.server.handler.RequestLogHandler">
<property name="requestLog" ref="jettyLog"/>
</bean>
<bean id="jettyLog" class="org.eclipse.jetty.server.Slf4jRequestLog"/>
并且像这样配置enpoint:
jetty:http://0.0.0.0:8040/test?handlers=#log
但默认情况下,记录器不会写入主体和所有标题。您应该使用自己的日志逻辑创建扩展AbstractLifeCycle的类并实现RequestLog。