Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging: Drop another deprecated Loggers method #34520

Merged
merged 7 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ public static Logger getLogger(Logger parentLogger, String s) {
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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void testClusterStateUpdateLogging() throws Exception {
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);
Expand Down Expand Up @@ -208,7 +209,7 @@ public void testLongClusterStateUpdateLogging() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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;
Expand Down Expand Up @@ -325,7 +326,7 @@ public void testClusterStateUpdateLogging() throws Exception {
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);
Expand Down Expand Up @@ -672,7 +673,7 @@ public void testLongClusterStateUpdateLogging() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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;
Expand Down Expand Up @@ -132,7 +133,7 @@ public void testRegularSettingUpdateIsFullyLogged() throws Exception {

private void assertExpectedLogMessages(Consumer<Logger> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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;
Expand Down Expand Up @@ -70,7 +71,7 @@ public boolean ignoreExceptions() {
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 {
Expand Down Expand Up @@ -101,7 +102,7 @@ public void testUpdateAutoThrottleSettings() throws Exception {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ public void testIndexWriterIFDInfoStream() throws IllegalAccessException, IOExce
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static Logger resolveLogger(String loggerName) {
if (loggerName.equalsIgnoreCase("_root")) {
return LogManager.getRootLogger();
}
return Loggers.getLogger(loggerName);
return LogManager.getLogger(loggerName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand All @@ -48,8 +47,8 @@ public void testCustomLevelPerMethod() throws Exception {

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();

Expand Down Expand Up @@ -80,13 +79,13 @@ public void testCustomLevelPerClass() throws Exception {

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();

Expand Down Expand Up @@ -125,8 +124,8 @@ public void testCustomLevelPerClassAndPerMethod() throws Exception {

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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -141,9 +142,9 @@ public void close() throws IOException {
@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);
Expand Down