Skip to content

LoggingApplicationListener: Trim trailing whitespace from value of logging.config #22078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
psytester opened this issue Jun 23, 2020 · 1 comment
Labels
type: enhancement A general enhancement
Milestone

Comments

@psytester
Copy link

In application.properties file I had ~ by mistake ~ a trailing space in property logging.config
That leads to an failed appication start.
Such simple config error should be automatically fixed by triming trailing whitespace from value of logging.config

Related code:
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java

	private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) {
		LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment);
		String logConfig = environment.getProperty(CONFIG_PROPERTY);
		if (ignoreLogConfig(logConfig)) {
			system.initialize(initializationContext, null, logFile);
		}
		else {
			try {
				// --->  here some trimTrailingWhitespace(logConfig)  <---
				ResourceUtils.getURL(logConfig).openStream().close();
				system.initialize(initializationContext, logConfig, logFile);
			}
			catch (Exception ex) {
				// NOTE: We can't use the logger here to report the problem
				System.err.println("Logging system failed to initialize using configuration from '" + logConfig + "'");
				ex.printStackTrace(System.err);
				throw new IllegalStateException(ex);
			}
		}
	}

logging.config=config/logback_apiserver.xml with trailing whitespace(s)

Current Stacktrace without trim trailing whitespace:

2020-06-23 13:09:37.975  INFO [,,,] 24824 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e6aaebb] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Logging system failed to initialize using configuration from 'config/logback.xml '
java.io.FileNotFoundException: /opt/myApplication/config/logback.xml  (No such file or directory)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
        at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86)
        at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:184)
        at java.base/java.net.URL.openStream(URL.java:1140)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:317)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:288)
......
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 23, 2020
@wilkinsona
Copy link
Member

Thanks for the suggestion.

We don't want to trim whitespace everywhere (#4106) but we have trimmed it in places where we feel that we can safely do so (#15972, for example). I think it's really unlikely that a logging config file's name would deliberately have trailing whitespace so it should be safe to trim it in this case. On the other hand, the current failure shows the problem so it's hopefully quite easy to identify it and fix it at source rather than relying on Boot tidying things up. Let's see what the rest of the team thinks.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue for: team-attention An issue we'd like other members of the team to review and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 23, 2020
@philwebb philwebb added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Jun 24, 2020
@philwebb philwebb added this to the 2.4.x milestone Jun 24, 2020
@mbhave mbhave modified the milestones: 2.4.x, 2.4.0-M1 Jun 25, 2020
@mbhave mbhave closed this as completed in c3ddfcd Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants