Skip to content
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

PropertySourceBootstrapConfiguration not reinitializeLoggingSystem if git properties not contains logging prefix attribute #392

Closed
gudegg opened this issue Jul 14, 2018 · 7 comments

Comments

@gudegg
Copy link

gudegg commented Jul 14, 2018

if my git properties

custom.logging.logpath=/usr/xxx
private void reinitializeLoggingSystem(ConfigurableEnvironment environment,
			String oldLogConfig, LogFile oldLogFile) {
		Map<String, Object> props = Binder.get(environment)
				.bind("logging", Bindable.mapOf(String.class, Object.class)).orElseGet(Collections::emptyMap);
              //If the custom key such as ‘custom.logging.logpath’ will not continue to call
		if (!props.isEmpty()) {
			String logConfig = environment.resolvePlaceholders("${logging.config:}");
			LogFile logFile = LogFile.get(environment);
			LoggingSystem system = LoggingSystem
					.get(LoggingSystem.class.getClassLoader());
			try {
				ResourceUtils.getURL(logConfig).openStream().close();
				// Three step initialization that accounts for the clean up of the logging
				// context before initialization. Spring Boot doesn't initialize a logging
				// system that hasn't had this sequence applied (since 1.4.1).
				system.cleanUp();
				system.beforeInitialize();
				system.initialize(new LoggingInitializationContext(environment),
						logConfig, logFile);
			}
			catch (Exception ex) {
				PropertySourceBootstrapConfiguration.logger
						.warn("Logging config file location '" + logConfig
								+ "' cannot be opened and will be ignored");
			}
		}
	}

logback-spring.xml

 <springProperty name="LOG_PATH" scope="context" source="custom.logging.logpath" defaultValue="/opt/logs"/>

    <appender name="ROOT_ROLLFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <pattern>${FILE_LOG_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/root.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>3</maxHistory>
        </rollingPolicy>
    </appender>
@marcingrzejszczak
Copy link
Contributor

You haven't provided almost any required information necessary to help you. Please provide a sample that replicates the problem

@gudegg
Copy link
Author

gudegg commented Jul 14, 2018

I want to replace the logback.xml property with spring cloud config. git repository,but not work,get defaultValue.

<springProperty name="LOG_PATH" scope="context" source="custom.logging.logpath" defaultValue="/opt/logs"/>

@marcingrzejszczak
Copy link
Contributor

Can you provide a full sample that replicates the problem?

@gudegg
Copy link
Author

gudegg commented Jul 14, 2018

sample.zip
Please check it out Thank you!

@ryanjbaxter
Copy link
Contributor

Without setting some kind of property that specifies the custom logging prefix I am not sure how we could identify the correct property.

@gudegg
Copy link
Author

gudegg commented Jul 17, 2018

can ignore the prefix every time it is refreshed, but this can be a bad practice

@ryanjbaxter
Copy link
Contributor

The team decided to add a note to the documentation about this limitation.
8465968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants