diff --git a/components-starter/camel-platform-http-starter/src/main/docs/platform-http.adoc b/components-starter/camel-platform-http-starter/src/main/docs/platform-http.adoc index d1f759cc493..24898a54bba 100644 --- a/components-starter/camel-platform-http-starter/src/main/docs/platform-http.adoc +++ b/components-starter/camel-platform-http-starter/src/main/docs/platform-http.adoc @@ -1,4 +1,4 @@ -= HTTP += Platform HTTP //Manually maintained attributes :artifactid: camel-platform-http :shortname: platform-http @@ -11,12 +11,12 @@ The Platform HTTP starter provides Spring Boot auto-configuration for the Camel You can enable Undertow access log to be managed by whatever logging library you have in your camel application, you have to set the following parameters: [source,properties] ---- -# disable the undertow access log handler +# disable the Undertow's own access log handler. server.undertow.accesslog.enabled=false -# optionally sets a log pattern (optional) +# sets a log pattern (optional) server.undertow.accesslog.pattern="%r" %s (%D ms) # enable camel to control the logging -camel.component.platform-http.server.accesslog.undertow.use-camel-logging=true +camel.component.platform-http.server.undertow.accesslog.use-camel-logging=true ---- The access log category is `io.undertow.accesslog` and is logged at `INFO` level. @@ -61,3 +61,5 @@ If you want to control the undertow access log category: ---- + +The HTTP access log message pattern may be controlled by the property: `server.undertow.accesslog.pattern` whose default value is `common`. diff --git a/components-starter/camel-platform-http-starter/src/main/docs/platform-http.json b/components-starter/camel-platform-http-starter/src/main/docs/platform-http.json index b611b25426d..641e67f14d7 100644 --- a/components-starter/camel-platform-http-starter/src/main/docs/platform-http.json +++ b/components-starter/camel-platform-http-starter/src/main/docs/platform-http.json @@ -12,7 +12,7 @@ "sourceMethod": "getCustomizer()" }, { - "name": "camel.component.platform-http.server.accesslog.undertow", + "name": "camel.component.platform-http.server.undertow.accesslog", "type": "org.apache.camel.component.platform.http.springboot.customizer.UndertowAccessLogProperties", "sourceType": "org.apache.camel.component.platform.http.springboot.customizer.UndertowAccessLogProperties" } @@ -76,7 +76,7 @@ "defaultValue": true }, { - "name": "camel.component.platform-http.server.accesslog.undertow.use-camel-logging", + "name": "camel.component.platform-http.server.undertow.accesslog.use-camel-logging", "type": "java.lang.Boolean", "description": "Use camel logging for undertow http access log.", "sourceType": "org.apache.camel.component.platform.http.springboot.customizer.UndertowAccessLogProperties", diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogConfiguration.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogConfiguration.java index a1eee5276c1..33f0bca01b9 100644 --- a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogConfiguration.java +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogConfiguration.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.platform.http.springboot.customizer; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -37,12 +38,12 @@ @ConditionalOnClass(name = "io.undertow.Undertow") @ConditionalOnProperties( { @ConditionalOnProperty(name = "server.undertow.accesslog.enabled", havingValue = "false"), - @ConditionalOnProperty(name = "camel.component.platform-http.server.accesslog.undertow.use-camel-logging", havingValue = "true"), + @ConditionalOnProperty(name = "camel.component.platform-http.server.undertow.accesslog.use-camel-logging", havingValue = "true"), }) public class UndertowAccessLogConfiguration { @Bean - WebServerFactoryCustomizer undertowManagementAccessLogCustomizer(Environment env) { + WebServerFactoryCustomizer undertowServerAccessLogCustomizer(Environment env) { return new WebServerFactoryCustomizer() { @Override public void customize(UndertowServletWebServerFactory factory) { diff --git a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogProperties.java b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogProperties.java index 616f7c18712..b217e504d70 100644 --- a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogProperties.java +++ b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/customizer/UndertowAccessLogProperties.java @@ -21,7 +21,7 @@ /** * Configuration properties to customize undertow server to use camel logging to log HTTP accesslog. */ -@ConfigurationProperties(prefix = "camel.component.platform-http.server.accesslog.undertow") +@ConfigurationProperties(prefix = "camel.component.platform-http.server.undertow.accesslog") public class UndertowAccessLogProperties { /** diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.adoc b/core/camel-spring-boot/src/main/docs/spring-boot.adoc index d73c825ce68..7fb0591679d 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.adoc +++ b/core/camel-spring-boot/src/main/docs/spring-boot.adoc @@ -69,7 +69,7 @@ public class MyRoute extends RouteBuilder { Then these routes will be started automatically. You can customize the Camel application in the `application.properties` -or `application.yml` file. +or `application.yml` file. // spring-boot-auto-configure options: START @@ -152,7 +152,7 @@ to http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-e Boot external configuration] (like properties placeholders, OS environment variables or system properties) with the Camel properties support. It basically means -that any property defined in `application.properties` file: +that any property defined in `application.properties` file: [source,properties] ---- @@ -487,6 +487,21 @@ management.server.accesslog.enabled=false Result: Main app logs to `logs/access_log.log`, actuator has no access logs. +==== Camel Logging to Control Management Access Log + +This is valid only when using `spring-boot-starter-undertow`. + +If you want to defer the http access log control to whatever camel logging mechanism, you have to set `management.server.undertow.accesslog.use-camel-logging=true`. +Optionally you can set a message pattern with `management.server.accesslog.pattern=combined`. + +Example: +[source,properties] +---- +management.server.undertow.accesslog.use-camel-logging=true +management.server.accesslog.pattern=combined +---- + + == Virtual Threads Support Camel Spring Boot provides comprehensive support for JDK 21+ Virtual Threads, offering significant performance improvements for I/O-intensive applications. Virtual threads are lightweight threads that can dramatically reduce memory overhead and improve scalability compared to traditional platform threads. @@ -596,7 +611,7 @@ If you need to manually configure specific components for virtual threads, you c ---- @Configuration public class VirtualThreadConfig { - + @Bean @ConditionalOnProperty(name = "spring.threads.virtual.enabled", havingValue = "true") public TaskExecutor customTaskExecutor() { @@ -638,11 +653,11 @@ camel.main.routes-include-pattern=classpath:routes/* ---- @SpringBootApplication public class VirtualThreadsApplication { - + public static void main(String[] args) { SpringApplication.run(VirtualThreadsApplication.class, args); } - + @Component public static class ApiRoutes extends RouteBuilder { @Override diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.json b/core/camel-spring-boot/src/main/docs/spring-boot.json index 3c29c379cda..f339b37a2bf 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.json +++ b/core/camel-spring-boot/src/main/docs/spring-boot.json @@ -2172,6 +2172,12 @@ "sourceType": "org.apache.camel.spring.boot.actuate.accesslog.ManagementAccessLogProperties", "defaultValue": true }, + { + "name": "management.server.accesslog.pattern", + "type": "java.lang.String", + "sourceType": "org.apache.camel.spring.boot.actuate.accesslog.ManagementAccessLogProperties", + "defaultValue": "common" + }, { "name": "camel.main.main-run-controller", "type": "java.lang.Boolean", diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogConfiguration.java index 8cf6231a380..dd3b9ee1702 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogConfiguration.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.spring.boot.actuate.accesslog; import org.apache.catalina.valves.AccessLogValve; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -28,6 +29,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import io.undertow.server.handlers.accesslog.AccessLogHandler; +import io.undertow.server.handlers.accesslog.JBossLoggingAccessLogReceiver; + /** * Management context configuration for controlling access logging on the management server. *

@@ -41,17 +45,33 @@ public class ManagementAccessLogConfiguration { /** - * Undertow-specific configuration to disable access logging in the management context. + * Undertow-specific configuration. */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(name = "io.undertow.Undertow") - @ConditionalOnProperty(name = "management.server.accesslog.enabled", havingValue = "false") static class UndertowAccessLogCustomizerConfiguration { + /** + * Disable access logging in the management context. + */ @Bean + @ConditionalOnProperty(name = "management.server.accesslog.enabled", havingValue = "false") WebServerFactoryCustomizer undertowManagementAccessLogCustomizer() { return factory -> factory.setAccessLogEnabled(false); } + + /** + * Undertow HTTP access log is managed by whatever camel logging mechanism. + */ + @Bean + @ConditionalOnProperty(name = "management.server.undertow.accesslog.use-camel-logging", havingValue = "true") + public WebServerFactoryCustomizer managementAccessLogProvider( + @Value("${management.server.accesslog.pattern:common}") String pattern) { + return factory -> factory.addDeploymentInfoCustomizers(deploymentInfo -> { + deploymentInfo.addInitialHandlerChainWrapper(handler -> new AccessLogHandler(handler, + new JBossLoggingAccessLogReceiver(), pattern, AccessLogHandler.class.getClassLoader())); + }); + } } /** diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogProperties.java index 9c9c57055b3..439305cd84e 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogProperties.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogProperties.java @@ -29,6 +29,7 @@ public class ManagementAccessLogProperties { * access logs are disabled for actuator endpoints. */ private boolean enabled = true; + private String pattern = "common"; public boolean isEnabled() { return enabled; @@ -37,4 +38,13 @@ public boolean isEnabled() { public void setEnabled(boolean enabled) { this.enabled = enabled; } + + public String getPattern() { + return pattern; + } + + public void setPattern(String pattern) { + this.pattern = pattern; + } + }