This is an automated email from the ASF dual-hosted git repository. fmariani pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit 1a2185eaddcdba5f15ef2f9cb266caeee35bb4d0 Author: Croway <[email protected]> AuthorDate: Mon Feb 2 11:37:59 2026 +0100 CAMEL-22946: make it easier to write application access logs only, without management access logs --- core/camel-spring-boot/pom.xml | 14 ++++ .../src/main/docs/spring-boot.adoc | 43 +++++++++++ .../src/main/docs/spring-boot.json | 12 ++++ .../JettyManagementAccessLogCustomizer.java | 40 +++++++++++ .../ManagementAccessLogConfiguration.java | 84 ++++++++++++++++++++++ .../accesslog/ManagementAccessLogProperties.java | 40 +++++++++++ .../additional-spring-configuration-metadata.json | 6 ++ ...gure.web.ManagementContextConfiguration.imports | 18 +++++ 8 files changed, 257 insertions(+) diff --git a/core/camel-spring-boot/pom.xml b/core/camel-spring-boot/pom.xml index 66633fc44cd..722faa8b40a 100644 --- a/core/camel-spring-boot/pom.xml +++ b/core/camel-spring-boot/pom.xml @@ -68,6 +68,20 @@ <version>${spring-boot-version}</version> <optional>true</optional> </dependency> + <!-- Optional Undertow support for management access log configuration --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + <version>${spring-boot-version}</version> + <optional>true</optional> + </dependency> + <!-- Optional Jetty support for management access log configuration --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + <version>${spring-boot-version}</version> + <optional>true</optional> + </dependency> <dependency> <groupId>org.apache.camel</groupId> 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 675e087ae04..8e812b0e9dd 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.adoc +++ b/core/camel-spring-boot/src/main/docs/spring-boot.adoc @@ -456,6 +456,49 @@ management.endpoint.health.probes.enabled=true Finally, http://localhost:8080/actuator/health/liveness will show the updated probe. +== Management Access Log Control + +When running actuator endpoints on a separate management port, you can disable access logging for the management context while keeping access logs for the main application. This is useful to avoid cluttering access logs with health check requests. + +NOTE: This feature requires `management.server.port` to be different from the main application port. + +=== Tomcat + +[source,properties] +---- +server.tomcat.accesslog.enabled=true +server.tomcat.accesslog.directory=logs +server.tomcat.basedir=./target +management.server.port=9090 +management.server.accesslog.enabled=false +---- + +Result: Main app logs to `./target/logs/access_log.<date>.log`, actuator has no access logs. + +=== Undertow + +[source,properties] +---- +server.undertow.accesslog.enabled=true +server.undertow.accesslog.dir=logs +management.server.port=9090 +management.server.accesslog.enabled=false +---- + +Result: Main app logs to `logs/access_log.log`, actuator has no access logs. + +=== Jetty + +[source,properties] +---- +server.jetty.accesslog.enabled=true +server.jetty.accesslog.filename=./target/logs/jetty_access.log +management.server.port=9090 +management.server.accesslog.enabled=false +---- + +Result: Main app logs to `./target/logs/jetty_access.log`, actuator has no access logs. + == 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. 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 0103b64cc9e..3c29c379cda 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.json +++ b/core/camel-spring-boot/src/main/docs/spring-boot.json @@ -189,6 +189,11 @@ "name": "management.endpoint.camelroutes", "type": "org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpointProperties", "sourceType": "org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpointProperties" + }, + { + "name": "management.server.accesslog", + "type": "org.apache.camel.spring.boot.actuate.accesslog.ManagementAccessLogProperties", + "sourceType": "org.apache.camel.spring.boot.actuate.accesslog.ManagementAccessLogProperties" } ], "properties": [ @@ -2160,6 +2165,13 @@ "description": "Whether to enable Camel info.", "defaultValue": true }, + { + "name": "management.server.accesslog.enabled", + "type": "java.lang.Boolean", + "description": "Whether access logging is enabled for the management server. When false and using a separate management port, access logs are disabled for actuator endpoints.", + "sourceType": "org.apache.camel.spring.boot.actuate.accesslog.ManagementAccessLogProperties", + "defaultValue": true + }, { "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/JettyManagementAccessLogCustomizer.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/JettyManagementAccessLogCustomizer.java new file mode 100644 index 00000000000..4b4f97cc1d8 --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/JettyManagementAccessLogCustomizer.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.boot.actuate.accesslog; + +import org.eclipse.jetty.server.Server; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; + +/** + * Jetty-specific customizer to disable access logging in the management context. + * <p> + * This class is separated from the main configuration to avoid class loading issues when Jetty is not on the classpath. + * It is only instantiated when Jetty classes are available. + * </p> + */ +public class JettyManagementAccessLogCustomizer implements WebServerFactoryCustomizer<JettyServletWebServerFactory> { + + @Override + public void customize(JettyServletWebServerFactory factory) { + factory.addServerCustomizers(this::disableAccessLog); + } + + private void disableAccessLog(Server server) { + server.setRequestLog(null); + } +} 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 new file mode 100644 index 00000000000..31ad35f8f41 --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogConfiguration.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.boot.actuate.accesslog; + +import org.apache.catalina.valves.AccessLogValve; +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Management context configuration for controlling access logging on the management server. + * <p> + * This configuration is only loaded in the management context (when management runs on a separate port) and provides + * customizers to disable access logging for actuator endpoints while keeping access logs for the main application. + * </p> + */ +@ManagementContextConfiguration(proxyBeanMethods = false) +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) +@EnableConfigurationProperties(ManagementAccessLogProperties.class) +public class ManagementAccessLogConfiguration { + + /** + * Undertow-specific configuration to disable access logging in the management context. + */ + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(name = "io.undertow.Undertow") + @ConditionalOnProperty(name = "management.server.accesslog.enabled", havingValue = "false") + static class UndertowAccessLogCustomizerConfiguration { + + @Bean + WebServerFactoryCustomizer<UndertowServletWebServerFactory> undertowManagementAccessLogCustomizer() { + return factory -> factory.setAccessLogEnabled(false); + } + } + + /** + * Tomcat-specific configuration to disable access logging in the management context. + */ + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(name = "org.apache.catalina.startup.Tomcat") + @ConditionalOnProperty(name = "management.server.accesslog.enabled", havingValue = "false") + static class TomcatAccessLogCustomizerConfiguration { + + @Bean + WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatManagementAccessLogCustomizer() { + return factory -> factory.getEngineValves().removeIf(valve -> valve instanceof AccessLogValve); + } + } + + /** + * Jetty-specific configuration to disable access logging in the management context. + */ + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(name = "org.eclipse.jetty.server.Server") + @ConditionalOnProperty(name = "management.server.accesslog.enabled", havingValue = "false") + static class JettyAccessLogCustomizerConfiguration { + + @Bean + JettyManagementAccessLogCustomizer jettyManagementAccessLogCustomizer() { + return new JettyManagementAccessLogCustomizer(); + } + } +} 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 new file mode 100644 index 00000000000..9c9c57055b3 --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/accesslog/ManagementAccessLogProperties.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.boot.actuate.accesslog; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Configuration properties for management server access logging. + */ +@ConfigurationProperties(prefix = "management.server.accesslog") +public class ManagementAccessLogProperties { + + /** + * Whether access logging is enabled for the management server. When false and using a separate management port, + * access logs are disabled for actuator endpoints. + */ + private boolean enabled = true; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } +} diff --git a/core/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/core/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json index d1fb7f9c406..ab8399f4045 100644 --- a/core/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/core/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -5,6 +5,12 @@ "type": "java.lang.Boolean", "description": "Whether to enable Camel info.", "defaultValue": true + }, + { + "name": "management.server.accesslog.enabled", + "type": "java.lang.Boolean", + "description": "Whether access logging is enabled for the management server. When false and using a separate management port, access logs are disabled for actuator endpoints.", + "defaultValue": true } ] } diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports new file mode 100644 index 00000000000..7207f0f90cd --- /dev/null +++ b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +org.apache.camel.spring.boot.actuate.accesslog.ManagementAccessLogConfiguration
