下面列出了怎么用org.springframework.boot.context.logging.LoggingApplicationListener的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
if (executed.compareAndSet(false, true)) {
String logConfig = environment.getProperty(LoggingApplicationListener.CONFIG_PROPERTY);
if (StringUtils.isEmpty(logConfig)) {
URL url = LogbackListener.class.getResource(LOGBACK_CFG_NAME);
String filePath = url.getPath();
if (filePath.indexOf(ResourceUtils.JAR_FILE_EXTENSION) > -1) {
filePath = ResourceUtils.JAR_URL_PREFIX + filePath;
}
System.setProperty(LoggingApplicationListener.CONFIG_PROPERTY, filePath);
}
}
}
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
if (executed.compareAndSet(false, true)) {
String logConfig = environment.getProperty(LoggingApplicationListener.CONFIG_PROPERTY);
if (StringUtils.isEmpty(logConfig)) {
URL url = LogbackListener.class.getResource(LOGBACK_CFG_NAME);
String filePath = url.getPath();
if (filePath.indexOf(ResourceUtils.JAR_FILE_EXTENSION) > -1) {
filePath = ResourceUtils.JAR_URL_PREFIX + filePath;
}
System.setProperty(LoggingApplicationListener.CONFIG_PROPERTY, filePath);
}
}
}
@Override
public int getOrder() {
return LoggingApplicationListener.DEFAULT_ORDER > Ordered.HIGHEST_PRECEDENCE
? LoggingApplicationListener.DEFAULT_ORDER - 1
: Ordered.HIGHEST_PRECEDENCE;
}
private Collection<? extends ApplicationListener<?>> filterListeners(
Set<ApplicationListener<?>> listeners) {
Set<ApplicationListener<?>> result = new LinkedHashSet<>();
for (ApplicationListener<?> listener : listeners) {
if (!(listener instanceof LoggingApplicationListener)
&& !(listener instanceof LoggingSystemShutdownListener)) {
result.add(listener);
}
}
return result;
}
@Override
public int getOrder() {
return LoggingApplicationListener.DEFAULT_ORDER - 1;
}
@Override
public int getOrder() {
return LoggingApplicationListener.DEFAULT_ORDER - 1;
}
@Test
public void getOrderReturnsHigherPrecedenceThanSpringBootLoggingApplicationListenerOrderByDefault() {
assertThat(this.listener.getOrder()).isLessThan(new LoggingApplicationListener().getOrder());
}