mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
🐛 Fixing ApplicationLoggerInitializer use EnvironmentPostProcessor
This commit is contained in:
1 parent
5548f11100
commit
be996be280
1 file changed
+12
-8
+12
-8
@@ -1,26 +1,30 @@
|
|||||||
package com.pig4cloud.pigx.common.log.init;
|
package com.pig4cloud.pigx.common.log.init;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
* @date 2019-05-22
|
* @date 2019-05-22
|
||||||
* <p>
|
* <p>
|
||||||
* 初始化日志路径
|
* 通过环境变量的形式注入 logging.file 自动维护 Spring Boot Admin Logger Viewer
|
||||||
*/
|
*/
|
||||||
public class ApplicationLoggerInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
public class ApplicationLoggerInitializer implements EnvironmentPostProcessor, Ordered {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
|
||||||
|
|
||||||
String appName = environment.getProperty("spring.application.name");
|
String appName = environment.getProperty("spring.application.name");
|
||||||
|
|
||||||
String logBase = environment.getProperty("LOGGING_PATH", "logs");
|
String logBase = environment.getProperty("LOGGING_PATH", "logs");
|
||||||
|
|
||||||
// spring boot admin 直接加载日志
|
// spring boot admin 直接加载日志
|
||||||
System.setProperty("logging.file.name", String.format("%s/%s/debug.log", logBase, appName));
|
System.setProperty("logging.file.name", String.format("%s/%s/debug.log", logBase, appName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return Ordered.LOWEST_PRECEDENCE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user