Skip to content

Commit

Permalink
Logging: Drop two deprecated methods (elastic#34055)
Browse files Browse the repository at this point in the history
This drops two deprecated methods from `ESLoggerFactory`, switching all
calls to those methods to calls to methods of the same name on
`LogManager`.
  • Loading branch information
nik9000 committed Sep 26, 2018
1 parent 3c2841d commit ddce970
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
package org.elasticsearch.client.benchmark.ops.bulk;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.client.benchmark.BenchmarkTask;
import org.elasticsearch.client.benchmark.metrics.Sample;
import org.elasticsearch.client.benchmark.metrics.SampleRecorder;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.logging.ESLoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -135,7 +135,7 @@ private void sendBulk(List<String> bulkData) throws InterruptedException {


private static final class BulkIndexer implements Runnable {
private static final Logger logger = ESLoggerFactory.getLogger(BulkIndexer.class.getName());
private static final Logger logger = LogManager.getLogger(BulkIndexer.class);

private final BlockingQueue<List<String>> bulkData;
private final int warmupIterations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
import com.amazonaws.services.ec2.model.UpdateSecurityGroupRuleDescriptionsIngressResult;
import com.amazonaws.services.ec2.waiters.AmazonEC2Waiters;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.apache.logging.log4j.LogManager;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -521,7 +521,7 @@

public class AmazonEC2Mock implements AmazonEC2 {

private static final Logger logger = ESLoggerFactory.getLogger(AmazonEC2Mock.class.getName());
private static final Logger logger = LogManager.getLogger(AmazonEC2Mock.class);

public static final String PREFIX_PRIVATE_IP = "10.0.0.";
public static final String PREFIX_PUBLIC_IP = "8.8.8.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.discovery.gce;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.testing.auth.oauth2.MockGoogleCredential;
import com.google.api.client.http.HttpBackOffIOExceptionHandler;
Expand All @@ -29,19 +31,14 @@
import com.google.api.client.http.HttpUnsuccessfulResponseHandler;
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.client.util.Sleeper;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.cloud.gce.util.Access;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.unit.TimeValue;

import java.io.IOException;
import java.util.Objects;

public class RetryHttpInitializerWrapper implements HttpRequestInitializer {

private TimeValue maxWait;

private static final Logger logger = ESLoggerFactory.getLogger(RetryHttpInitializerWrapper.class.getName());
private static final Logger logger = LogManager.getLogger(RetryHttpInitializerWrapper.class);

// Intercepts the request for filling in the "Authorization"
// header field, as well as recovering from certain unsuccessful
Expand All @@ -52,6 +49,8 @@ public class RetryHttpInitializerWrapper implements HttpRequestInitializer {
// A sleeper; you can replace it with a mock in your test.
private final Sleeper sleeper;

private TimeValue maxWait;

public RetryHttpInitializerWrapper(Credential wrappedCredential) {
this(wrappedCredential, Sleeper.DEFAULT, TimeValue.timeValueMillis(ExponentialBackOff.DEFAULT_MAX_ELAPSED_TIME_MILLIS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void tearDown() throws Exception {
}

public void testResolveMultipleConfigs() throws Exception {
final Level level = ESLoggerFactory.getLogger("test").getLevel();
final Level level = LogManager.getLogger("test").getLevel();
try {
final Path configDir = getDataPath("config");
final Settings settings = Settings.builder()
Expand Down Expand Up @@ -106,7 +106,7 @@ public void testDefaults() throws IOException, UserException {
LogConfigurator.configure(environment);

final String loggerName = "test";
final Logger logger = ESLoggerFactory.getLogger(loggerName);
final Logger logger = LogManager.getLogger(loggerName);
assertThat(logger.getLevel().toString(), equalTo(level));
}

Expand All @@ -122,7 +122,7 @@ public void testResolveOrder() throws Exception {

// args should overwrite whatever is in the config
final String loggerName = "test_resolve_order";
final Logger logger = ESLoggerFactory.getLogger(loggerName);
final Logger logger = LogManager.getLogger(loggerName);
assertTrue(logger.isTraceEnabled());
}

Expand All @@ -134,14 +134,14 @@ public void testHierarchy() throws Exception {
final Environment environment = new Environment(settings, configDir);
LogConfigurator.configure(environment);

assertThat(ESLoggerFactory.getLogger("x").getLevel(), equalTo(Level.TRACE));
assertThat(ESLoggerFactory.getLogger("x.y").getLevel(), equalTo(Level.DEBUG));
assertThat(LogManager.getLogger("x").getLevel(), equalTo(Level.TRACE));
assertThat(LogManager.getLogger("x.y").getLevel(), equalTo(Level.DEBUG));

final Level level = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR);
Loggers.setLevel(ESLoggerFactory.getLogger("x"), level);
Loggers.setLevel(LogManager.getLogger("x"), level);

assertThat(ESLoggerFactory.getLogger("x").getLevel(), equalTo(level));
assertThat(ESLoggerFactory.getLogger("x.y").getLevel(), equalTo(level));
assertThat(LogManager.getLogger("x").getLevel(), equalTo(level));
assertThat(LogManager.getLogger("x.y").getLevel(), equalTo(level));
}

public void testMissingConfigFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void tearDown() throws Exception {
public void testLocationInfoTest() throws IOException, UserException {
setupLogging("location_info");

final Logger testLogger = ESLoggerFactory.getLogger("test");
final Logger testLogger = LogManager.getLogger("test");

testLogger.error("This is an error message");
testLogger.warn("This is a warning message");
Expand All @@ -108,7 +108,7 @@ public void testLocationInfoTest() throws IOException, UserException {
public void testDeprecationLogger() throws IOException, UserException {
setupLogging("deprecation");

final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger("deprecation"));
final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger("deprecation"));

final int deprecatedIterations = randomIntBetween(0, 256);
for (int i = 0; i < deprecatedIterations; i++) {
Expand All @@ -135,7 +135,7 @@ public void testDeprecationLogger() throws IOException, UserException {
public void testConcurrentDeprecationLogger() throws IOException, UserException, BrokenBarrierException, InterruptedException {
setupLogging("deprecation");

final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger("deprecation"));
final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger("deprecation"));

final int numberOfThreads = randomIntBetween(2, 4);
final CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads);
Expand Down Expand Up @@ -214,7 +214,7 @@ public void testConcurrentDeprecationLogger() throws IOException, UserException,
public void testDeprecationLoggerMaybeLog() throws IOException, UserException {
setupLogging("deprecation");

final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger("deprecation"));
final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger("deprecation"));

final int iterations = randomIntBetween(1, 16);

Expand Down Expand Up @@ -286,12 +286,12 @@ public void testDeprecatedSettings() throws IOException, UserException {
public void testFindAppender() throws IOException, UserException {
setupLogging("find_appender");

final Logger hasConsoleAppender = ESLoggerFactory.getLogger("has_console_appender");
final Logger hasConsoleAppender = LogManager.getLogger("has_console_appender");

final Appender testLoggerConsoleAppender = Loggers.findAppender(hasConsoleAppender, ConsoleAppender.class);
assertNotNull(testLoggerConsoleAppender);
assertThat(testLoggerConsoleAppender.getName(), equalTo("console"));
final Logger hasCountingNoOpAppender = ESLoggerFactory.getLogger("has_counting_no_op_appender");
final Logger hasCountingNoOpAppender = LogManager.getLogger("has_counting_no_op_appender");
assertNull(Loggers.findAppender(hasCountingNoOpAppender, ConsoleAppender.class));
final Appender countingNoOpAppender = Loggers.findAppender(hasCountingNoOpAppender, CountingNoOpAppender.class);
assertThat(countingNoOpAppender.getName(), equalTo("counting_no_op"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package org.elasticsearch.smoketest;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
Expand Down Expand Up @@ -69,7 +69,7 @@ public abstract class ESSmokeClientTestCase extends LuceneTestCase {
*/
public static final String TESTS_CLUSTER = "tests.cluster";

protected static final Logger logger = ESLoggerFactory.getLogger(ESSmokeClientTestCase.class.getName());
protected static final Logger logger = LogManager.getLogger(ESSmokeClientTestCase.class);

private static final AtomicInteger counter = new AtomicInteger();
private static Client client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static void init(
final boolean closeStandardStreams = (foreground == false) || quiet;
try {
if (closeStandardStreams) {
final Logger rootLogger = ESLoggerFactory.getRootLogger();
final Logger rootLogger = LogManager.getRootLogger();
final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class);
if (maybeConsoleAppender != null) {
Loggers.removeAppender(rootLogger, maybeConsoleAppender);
Expand Down Expand Up @@ -339,7 +339,7 @@ static void init(
}
} catch (NodeValidationException | RuntimeException e) {
// disable console logging, so user does not see the exception twice (jvm will show it already)
final Logger rootLogger = ESLoggerFactory.getRootLogger();
final Logger rootLogger = LogManager.getRootLogger();
final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class);
if (foreground && maybeConsoleAppender != null) {
Loggers.removeAppender(rootLogger, maybeConsoleAppender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.locationtech.jts.geom.GeometryFactory;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.Assertions;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
Expand All @@ -32,7 +33,6 @@
import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
Expand All @@ -54,7 +54,7 @@
*/
public abstract class ShapeBuilder<T extends Shape, E extends ShapeBuilder<T,E>> implements NamedWriteable, ToXContentObject {

protected static final Logger LOGGER = ESLoggerFactory.getLogger(ShapeBuilder.class.getName());
protected static final Logger LOGGER = LogManager.getLogger(ShapeBuilder.class);

private static final boolean DEBUG;
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,4 @@ public static Logger getLogger(String prefix, Logger logger) {
public static Logger getLogger(Class<?> clazz) {
return getLogger(null, clazz);
}

/**
* Get or build a logger.
* @deprecated Prefer {@link LogManager#getLogger}
*/
@Deprecated
public static Logger getLogger(String name) {
return getLogger(null, name);
}

/**
* Get the root logger.
* @deprecated Prefer {@link LogManager#getRootLogger}
*/
@Deprecated
public static Logger getRootLogger() {
return LogManager.getRootLogger();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ private static void configureStatusLogger() {
private static void configureLoggerLevels(final Settings settings) {
if (Loggers.LOG_DEFAULT_LEVEL_SETTING.exists(settings)) {
final Level level = Loggers.LOG_DEFAULT_LEVEL_SETTING.get(settings);
Loggers.setLevel(ESLoggerFactory.getRootLogger(), level);
Loggers.setLevel(LogManager.getRootLogger(), level);
}
Loggers.LOG_LEVEL_SETTING.getAllConcreteSettings(settings)
// do not set a log level for a logger named level (from the default log setting)
.filter(s -> s.getKey().equals(Loggers.LOG_DEFAULT_LEVEL_SETTING.getKey()) == false).forEach(s -> {
final Level level = s.get(settings);
Loggers.setLevel(ESLoggerFactory.getLogger(s.getKey().substring("logger.".length())), level);
Loggers.setLevel(LogManager.getLogger(s.getKey().substring("logger.".length())), level);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static Logger getLogger(Logger parentLogger, String s) {
*/
@Deprecated
public static Logger getLogger(String s) {
return ESLoggerFactory.getLogger(s);
return LogManager.getLogger(s);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.elasticsearch.common.settings;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
import org.elasticsearch.action.search.TransportSearchAction;
import org.elasticsearch.action.support.AutoCreateIndex;
Expand All @@ -44,7 +45,6 @@
import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.network.NetworkService;
Expand Down Expand Up @@ -158,12 +158,12 @@ public void apply(Settings value, Settings current, Settings previous) {
if ("_root".equals(component)) {
final String rootLevel = value.get(key);
if (rootLevel == null) {
Loggers.setLevel(ESLoggerFactory.getRootLogger(), Loggers.LOG_DEFAULT_LEVEL_SETTING.get(settings));
Loggers.setLevel(LogManager.getRootLogger(), Loggers.LOG_DEFAULT_LEVEL_SETTING.get(settings));
} else {
Loggers.setLevel(ESLoggerFactory.getRootLogger(), rootLevel);
Loggers.setLevel(LogManager.getRootLogger(), rootLevel);
}
} else {
Loggers.setLevel(ESLoggerFactory.getLogger(component), value.get(key));
Loggers.setLevel(LogManager.getLogger(component), value.get(key));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package org.elasticsearch.discovery;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.logging.ESLoggerFactory;

import java.util.Set;

Expand All @@ -32,7 +32,7 @@
*/
public class AckClusterStatePublishResponseHandler extends BlockingClusterStatePublishResponseHandler {

private static final Logger logger = ESLoggerFactory.getLogger(AckClusterStatePublishResponseHandler.class.getName());
private static final Logger logger = LogManager.getLogger(AckClusterStatePublishResponseHandler.class);

private final Discovery.AckListener ackListener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
package org.elasticsearch.rest;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
Expand Down Expand Up @@ -117,7 +117,7 @@ public RestStatus status() {
return this.status;
}

private static final Logger SUPPRESSED_ERROR_LOGGER = ESLoggerFactory.getLogger("rest.suppressed");
private static final Logger SUPPRESSED_ERROR_LOGGER = LogManager.getLogger("rest.suppressed");

private static XContentBuilder build(RestChannel channel, RestStatus status, Exception e) throws IOException {
ToXContent.Params params = channel.request();
Expand Down
Loading

0 comments on commit ddce970

Please sign in to comment.