2121
2222import co .elastic .logstash .api .DeprecationLogger ;
2323import org .apache .logging .log4j .LogManager ;
24+ import org .apache .logging .log4j .Logger ;
2425import 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