From b093116a1e82e8e06c3ae61dc841a30304193785 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 29 Oct 2018 10:05:24 -0400 Subject: [PATCH] Logging: Drop another deprecated Loggers method (#34520) Drop a method from `Loggers` that we deprecated because it just delegated to `LogManager`. --- .../netty4/Netty4InternalESLogger.java | 4 ++-- .../elasticsearch/common/logging/Loggers.java | 9 --------- .../service/ClusterApplierServiceTests.java | 5 +++-- .../cluster/service/MasterServiceTests.java | 5 +++-- .../common/settings/SettingsFilterTests.java | 3 ++- .../index/MergeSchedulerSettingsTests.java | 5 +++-- .../index/engine/InternalEngineTests.java | 2 +- .../test/junit/listeners/LoggingListener.java | 2 +- .../test/test/LoggingListenerTests.java | 17 ++++++++--------- .../authc/saml/SamlMetadataCommand.java | 5 +++-- 10 files changed, 26 insertions(+), 31 deletions(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4InternalESLogger.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4InternalESLogger.java index 91bbe1c1a9b..d4b3aead0d2 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4InternalESLogger.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4InternalESLogger.java @@ -21,8 +21,8 @@ package org.elasticsearch.transport.netty4; import io.netty.util.internal.logging.AbstractInternalLogger; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.SuppressLoggerChecks; -import org.elasticsearch.common.logging.Loggers; @SuppressLoggerChecks(reason = "safely delegates to logger") class Netty4InternalESLogger extends AbstractInternalLogger { @@ -31,7 +31,7 @@ class Netty4InternalESLogger extends AbstractInternalLogger { Netty4InternalESLogger(final String name) { super(name); - this.logger = Loggers.getLogger(name); + this.logger = LogManager.getLogger(name); } @Override diff --git a/server/src/main/java/org/elasticsearch/common/logging/Loggers.java b/server/src/main/java/org/elasticsearch/common/logging/Loggers.java index e5031f4608e..28df6206e9b 100644 --- a/server/src/main/java/org/elasticsearch/common/logging/Loggers.java +++ b/server/src/main/java/org/elasticsearch/common/logging/Loggers.java @@ -76,15 +76,6 @@ public class Loggers { return ESLoggerFactory.getLogger(prefix, parentLogger.getName() + s); } - /** - * Get or build a logger. - * @deprecated Prefer {@link LogManager#getLogger} - */ - @Deprecated - public static Logger getLogger(String s) { - return LogManager.getLogger(s); - } - /** * Get or build a logger. * @deprecated Prefer {@link LogManager#getLogger} diff --git a/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java index cf278b80d9e..989b84f9f1a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.service; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -128,7 +129,7 @@ public class ClusterApplierServiceTests extends ESTestCase { Level.TRACE, "*failed to execute cluster state applier in [2s]*")); - Logger clusterLogger = Loggers.getLogger("org.elasticsearch.cluster.service"); + Logger clusterLogger = LogManager.getLogger("org.elasticsearch.cluster.service"); Loggers.addAppender(clusterLogger, mockAppender); try { final CountDownLatch latch = new CountDownLatch(3); @@ -208,7 +209,7 @@ public class ClusterApplierServiceTests extends ESTestCase { Level.WARN, "*cluster state applier task [test3] took [34s] above the warn threshold of *")); - Logger clusterLogger = Loggers.getLogger("org.elasticsearch.cluster.service"); + Logger clusterLogger = LogManager.getLogger("org.elasticsearch.cluster.service"); Loggers.addAppender(clusterLogger, mockAppender); try { final CountDownLatch latch = new CountDownLatch(4); diff --git a/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java index b95d7b301d8..26e36afc551 100644 --- a/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.service; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.cluster.AckedClusterStateUpdateTask; @@ -325,7 +326,7 @@ public class MasterServiceTests extends ESTestCase { Level.DEBUG, "*processing [test3]: took [3s] done publishing updated cluster state (version: *, uuid: *)")); - Logger clusterLogger = Loggers.getLogger(masterService.getClass().getPackage().getName()); + Logger clusterLogger = LogManager.getLogger(masterService.getClass().getPackage().getName()); Loggers.addAppender(clusterLogger, mockAppender); try { final CountDownLatch latch = new CountDownLatch(4); @@ -672,7 +673,7 @@ public class MasterServiceTests extends ESTestCase { Level.WARN, "*cluster state update task [test4] took [34s] above the warn threshold of *")); - Logger clusterLogger = Loggers.getLogger(masterService.getClass().getPackage().getName()); + Logger clusterLogger = LogManager.getLogger(masterService.getClass().getPackage().getName()); Loggers.addAppender(clusterLogger, mockAppender); try { final CountDownLatch latch = new CountDownLatch(5); diff --git a/server/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java b/server/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java index e6b31d95c85..17939f07766 100644 --- a/server/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java +++ b/server/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.settings; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting.Property; @@ -132,7 +133,7 @@ public class SettingsFilterTests extends ESTestCase { private void assertExpectedLogMessages(Consumer consumer, MockLogAppender.LoggingExpectation ... expectations) throws IllegalAccessException { - Logger testLogger = Loggers.getLogger("org.elasticsearch.test"); + Logger testLogger = LogManager.getLogger("org.elasticsearch.test"); MockLogAppender appender = new MockLogAppender(); Loggers.addAppender(testLogger, appender); try { diff --git a/server/src/test/java/org/elasticsearch/index/MergeSchedulerSettingsTests.java b/server/src/test/java/org/elasticsearch/index/MergeSchedulerSettingsTests.java index e9eb5d8b83d..c3c2a8176e3 100644 --- a/server/src/test/java/org/elasticsearch/index/MergeSchedulerSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/index/MergeSchedulerSettingsTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.filter.RegexFilter; @@ -70,7 +71,7 @@ public class MergeSchedulerSettingsTests extends ESTestCase { public void testUpdateAutoThrottleSettings() throws Exception { MockAppender mockAppender = new MockAppender("testUpdateAutoThrottleSettings"); mockAppender.start(); - final Logger settingsLogger = Loggers.getLogger("org.elasticsearch.common.settings.IndexScopedSettings"); + final Logger settingsLogger = LogManager.getLogger("org.elasticsearch.common.settings.IndexScopedSettings"); Loggers.addAppender(settingsLogger, mockAppender); Loggers.setLevel(settingsLogger, Level.TRACE); try { @@ -101,7 +102,7 @@ public class MergeSchedulerSettingsTests extends ESTestCase { public void testUpdateMergeMaxThreadCount() throws Exception { MockAppender mockAppender = new MockAppender("testUpdateAutoThrottleSettings"); mockAppender.start(); - final Logger settingsLogger = Loggers.getLogger("org.elasticsearch.common.settings.IndexScopedSettings"); + final Logger settingsLogger = LogManager.getLogger("org.elasticsearch.common.settings.IndexScopedSettings"); Loggers.addAppender(settingsLogger, mockAppender); Loggers.setLevel(settingsLogger, Level.TRACE); try { diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index efbce034de4..deb2f4c5496 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -2368,7 +2368,7 @@ public class InternalEngineTests extends EngineTestCase { MockAppender mockAppender = new MockAppender("testIndexWriterIFDInfoStream"); mockAppender.start(); - final Logger iwIFDLogger = Loggers.getLogger("org.elasticsearch.index.engine.Engine.IFD"); + final Logger iwIFDLogger = LogManager.getLogger("org.elasticsearch.index.engine.Engine.IFD"); Loggers.addAppender(iwIFDLogger, mockAppender); Loggers.setLevel(iwIFDLogger, Level.DEBUG); diff --git a/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/LoggingListener.java b/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/LoggingListener.java index eb300ba302b..5f64bcc21df 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/LoggingListener.java +++ b/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/LoggingListener.java @@ -80,7 +80,7 @@ public class LoggingListener extends RunListener { if (loggerName.equalsIgnoreCase("_root")) { return LogManager.getRootLogger(); } - return Loggers.getLogger(loggerName); + return LogManager.getLogger(loggerName); } /** diff --git a/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java b/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java index fe5dedb2d5a..90c74211089 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java @@ -22,7 +22,6 @@ package org.elasticsearch.test.test; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; -import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.junit.listeners.LoggingListener; @@ -48,8 +47,8 @@ public class LoggingListenerTests extends ESTestCase { Description suiteDescription = Description.createSuiteDescription(TestClass.class); - Logger xyzLogger = Loggers.getLogger("xyz"); - Logger abcLogger = Loggers.getLogger("abc"); + Logger xyzLogger = LogManager.getLogger("xyz"); + Logger abcLogger = LogManager.getLogger("abc"); final Level level = LogManager.getRootLogger().getLevel(); @@ -80,13 +79,13 @@ public class LoggingListenerTests extends ESTestCase { Description suiteDescription = Description.createSuiteDescription(AnnotatedTestClass.class); - Logger abcLogger = Loggers.getLogger("abc"); - Logger xyzLogger = Loggers.getLogger("xyz"); + Logger abcLogger = LogManager.getLogger("abc"); + Logger xyzLogger = LogManager.getLogger("xyz"); // we include foo and foo.bar to maintain that logging levels are applied from the top of the hierarchy down; this ensures that // setting the logging level for a parent logger and a child logger applies the parent level first and then the child as otherwise // setting the parent level would overwrite the child level - Logger fooLogger = Loggers.getLogger("foo"); - Logger fooBarLogger = Loggers.getLogger("foo.bar"); + Logger fooLogger = LogManager.getLogger("foo"); + Logger fooBarLogger = LogManager.getLogger("foo.bar"); final Level level = LogManager.getRootLogger().getLevel(); @@ -125,8 +124,8 @@ public class LoggingListenerTests extends ESTestCase { Description suiteDescription = Description.createSuiteDescription(AnnotatedTestClass.class); - Logger abcLogger = Loggers.getLogger("abc"); - Logger xyzLogger = Loggers.getLogger("xyz"); + Logger abcLogger = LogManager.getLogger("abc"); + Logger xyzLogger = LogManager.getLogger("xyz"); final Level level = LogManager.getRootLogger().getLevel(); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlMetadataCommand.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlMetadataCommand.java index 9aad0272f48..eacae4621ba 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlMetadataCommand.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlMetadataCommand.java @@ -31,6 +31,7 @@ import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.cli.EnvironmentAwareCommand; import org.elasticsearch.cli.ExitCodes; import org.elasticsearch.cli.SuppressForbidden; @@ -141,9 +142,9 @@ public class SamlMetadataCommand extends EnvironmentAwareCommand { @Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { // OpenSAML prints a lot of _stuff_ at info level, that really isn't needed in a command line tool. - Loggers.setLevel(Loggers.getLogger("org.opensaml"), Level.WARN); + Loggers.setLevel(LogManager.getLogger("org.opensaml"), Level.WARN); - final Logger logger = Loggers.getLogger(getClass()); + final Logger logger = LogManager.getLogger(getClass()); SamlUtils.initialize(logger); final EntityDescriptor descriptor = buildEntityDescriptor(terminal, options, env);