io.irain.reactor.logging.autoconfigure.LoggingInitializer Maven / Gradle / Ivy
The newest version!
package io.irain.reactor.logging.autoconfigure;
import io.irain.reactor.logging.utils.LoggingUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* logging 日志初始化
*
* @author youta
*/
@Component
public class LoggingInitializer implements EnvironmentPostProcessor, Ordered {
/**
* 用于 spring boot admin 中展示日志
*/
public static final String LOGGING_FILE_PATH_KEY = "logging.file.path";
/**
* 用于 spring boot admin 中展示日志
*/
public static final String LOGGING_FILE_NAME_KEY = "logging.file.name";
/**
* 用于 spring boot admin 中展示日志
*/
public static final String SHORE_LOGGING_PROPERTY_SOURCE_NAME = "shoreLoggingPropertySource";
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
// 读取系统配置的日志目录,默认为项目下 logs
String logBase = environment.getProperty(LOGGING_FILE_PATH_KEY, LoggingUtil.DEFAULT_LOG_DIR);
// 用于 spring boot admin 中展示日志
if (!environment.containsProperty(LOGGING_FILE_NAME_KEY)) {
Map map = new HashMap<>(2);
map.put(LOGGING_FILE_NAME_KEY, logBase + "/${spring.application.name}/" + LoggingUtil.LOG_FILE_ALL);
MapPropertySource propertySource = new MapPropertySource(SHORE_LOGGING_PROPERTY_SOURCE_NAME, map);
environment.getPropertySources().addLast(propertySource);
}
}
@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy