Commit 76a1295e authored by liaozan's avatar liaozan 🏀

Ensure the PropertiesPreparedEventListener can print log correctly

parent a1c2069a
......@@ -35,10 +35,13 @@ class ConfigurablePropertiesLoader {
*/
private static final String PROPERTIES_PROPERTY_SOURCE = "ConfigurablePropertiesPropertySource";
private final DeferredLogFactory deferredLogFactory;
private final Log log;
ConfigurablePropertiesLoader(DeferredLogFactory logFactory) {
this.log = logFactory.getLog(ConfigurablePropertiesLoader.class);
ConfigurablePropertiesLoader(DeferredLogFactory deferredLogFactory) {
this.deferredLogFactory = deferredLogFactory;
this.log = deferredLogFactory.getLog(ConfigurablePropertiesLoader.class);
}
void load(ConfigurableEnvironment environment, SpringApplication application) {
......@@ -74,7 +77,7 @@ class ConfigurablePropertiesLoader {
compositePropertySource.addPropertySource(propertySource);
ConfigurableProperties boundProperties = properties.bind(environment);
eventMulticaster.multicastEvent(new PropertiesPreparedEvent(boundProperties, propertySource, environment, application));
eventMulticaster.multicastEvent(new PropertiesPreparedEvent(environment, deferredLogFactory, propertySource, boundProperties, application));
});
}
......
......@@ -4,6 +4,7 @@ import com.schbrain.common.util.properties.SchbrainMapPropertySource;
import com.schbrain.common.util.support.ConfigurableProperties;
import lombok.Getter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.env.ConfigurableEnvironment;
......@@ -18,15 +19,21 @@ public class PropertiesPreparedEvent extends ApplicationEvent {
private final ConfigurableEnvironment environment;
private final DeferredLogFactory deferredLogFactory;
private final SchbrainMapPropertySource propertySource;
private final SpringApplication application;
public PropertiesPreparedEvent(ConfigurableProperties properties, SchbrainMapPropertySource propertySource,
ConfigurableEnvironment environment, SpringApplication application) {
public PropertiesPreparedEvent(ConfigurableEnvironment environment,
DeferredLogFactory deferredLogFactory,
SchbrainMapPropertySource propertySource,
ConfigurableProperties properties,
SpringApplication application) {
super(properties);
this.environment = environment;
this.propertySource = propertySource;
this.deferredLogFactory = deferredLogFactory;
this.application = application;
}
......
package com.schbrain.framework.autoconfigure.apollo.listener;
import com.schbrain.common.util.support.ConfigurableProperties;
import org.apache.commons.logging.Log;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
......@@ -14,6 +15,8 @@ public class PropertiesPreparedEventListenerAdapter<T extends ConfigurableProper
private final Class<T> propertyType;
protected Log log;
public PropertiesPreparedEventListenerAdapter() {
ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass();
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
......@@ -23,7 +26,8 @@ public class PropertiesPreparedEventListenerAdapter<T extends ConfigurableProper
@Override
public void onApplicationEvent(PropertiesPreparedEvent event) {
if (event.getConfigurableProperties().getClass() == propertyType) {
onPropertiesPrepared(event, (T) event.getConfigurableProperties());
this.log = event.getDeferredLogFactory().getLog(this.getClass());
this.onPropertiesPrepared(event, (T) event.getConfigurableProperties());
}
}
......
......@@ -11,7 +11,6 @@ import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEv
import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEventListenerAdapter;
import com.schbrain.framework.autoconfigure.logger.LoggerConfigurationInitializer;
import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.StringUtils;
......@@ -25,7 +24,6 @@ import static org.springframework.boot.context.logging.LoggingApplicationListene
* @author liaozan
* @since 2023-04-28
*/
@Slf4j
public class LoggerPropertiesPreparedEventListener extends PropertiesPreparedEventListenerAdapter<LoggerProperties> {
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment