log4j2读取Application.yml中的配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
@Component public class LoggerListener implements ApplicationListener<ApplicationEvent>, Ordered { @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApplicationEnvironmentPreparedEvent) { ConfigurableEnvironment environment = ((ApplicationEnvironmentPreparedEvent) event).getEnvironment(); String property = environment.getProperty("spring.application.name"); System.setProperty("empower.log.path", property); } }
@Override public int getOrder() { return LoggingApplicationListener.DEFAULT_ORDER - 1; } }
|
启动类
1 2 3 4 5 6 7 8 9 10
| public class DataHubApplication {
public static void main(String[] args) { SpringApplication application = new SpringApplication(DataHubApplication.class); application.addListeners(new LoggerListener()); ConfigurableApplicationContext context = application.run(args); SpringBootUtils.setApplicationContent(context); } }
|
本文地址: https://github.com/maxzhao-it/blog/post/3c950ad/