Skip to content

Commit 08da681

Browse files
committed
Fixed deprecation log inside DeprecatedAlias following the principles of #16339 because loggers are active after the Settings instantiation
1 parent fa03765 commit 08da681

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

config/log4j2.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ appender.deprecation_rolling.policies.size.size = 100MB
154154
appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy
155155
appender.deprecation_rolling.strategy.max = 30
156156

157-
logger.deprecation.name = org.logstash.deprecation, deprecation
157+
logger.deprecation.name = org.logstash.deprecation
158158
logger.deprecation.level = WARN
159159
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_plain_rolling
160160
logger.deprecation.additivity = false

logstash-core/src/main/java/org/logstash/settings/DeprecatedAlias.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121

2222
import co.elastic.logstash.api.DeprecationLogger;
2323
import org.apache.logging.log4j.LogManager;
24+
import org.apache.logging.log4j.Logger;
2425
import org.logstash.log.DefaultDeprecationLogger;
2526

2627
/**
2728
* A <code>DeprecatedAlias</code> provides a deprecated alias for a setting, and is meant
2829
* to be used exclusively through @see org.logstash.settings.SettingWithDeprecatedAlias#wrap()
2930
* */
30-
final class DeprecatedAlias<T> extends SettingDelegator<T> {
31-
private final DeprecationLogger deprecationLogger = new DefaultDeprecationLogger(LogManager.getLogger(DeprecatedAlias.class));
31+
public final class DeprecatedAlias<T> extends SettingDelegator<T> {
32+
private static final Logger LOGGER = LogManager.getLogger();
33+
34+
private static final DeprecationLogger DEPRECATION_LOGGER = new DefaultDeprecationLogger(LOGGER);
3235

3336
private SettingWithDeprecatedAlias<T> canonicalProxy;
3437

@@ -37,16 +40,18 @@ final class DeprecatedAlias<T> extends SettingDelegator<T> {
3740
this.canonicalProxy = canonicalProxy;
3841
}
3942

40-
@Override
41-
public void setSafely(T newValue) {
42-
deprecationLogger.deprecated("The setting `{}` is a deprecated alias for `{}` and will be removed in a " +
43-
"future release of Logstash. Please use {} instead", getName(), canonicalProxy.getName(), canonicalProxy.getName());
44-
super.setSafely(newValue);
43+
// Because loggers are configure after the Settings declaration, this method is intended for lazy-logging
44+
// check https://github.com/elastic/logstash/pull/16339
45+
public void observePostProcess() {
46+
if (isSet()) {
47+
DEPRECATION_LOGGER.deprecated("The setting `{}` is a deprecated alias for `{}` and will be removed in a " +
48+
"future release of Logstash. Please use `{}` instead", getName(), canonicalProxy.getName(), canonicalProxy.getName());
49+
}
4550
}
4651

4752
@Override
4853
public T value() {
49-
deprecationLogger.deprecated("The value of setting `{}` has been queried by its deprecated alias `{}`. " +
54+
LOGGER.warn("The value of setting `{}` has been queried by its deprecated alias `{}`. " +
5055
"Code should be updated to query `{}` instead", canonicalProxy.getName(), getName(), canonicalProxy.getName());
5156
return super.value();
5257
}

0 commit comments

Comments
 (0)