Skip to content

Commit

Permalink
Cleanup redundant logger fields (#101655)
Browse files Browse the repository at this point in the history
Making loggers static that can be made static, removing redundant test
loggers (we already have the correct per class logger in this.logger)
and also removing some just unused loggers.
  • Loading branch information
original-brownbear authored Nov 2, 2023
1 parent 8485cd7 commit 995b4d3
Show file tree
Hide file tree
Showing 91 changed files with 82 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class ExportElasticsearchBuildResourcesTask extends DefaultTask {

private final Logger logger = Logging.getLogger(ExportElasticsearchBuildResourcesTask.class);
private static final Logger logger = Logging.getLogger(ExportElasticsearchBuildResourcesTask.class);

private final Set<String> resources = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class AzureBlobContainer extends AbstractBlobContainer {

private final Logger logger = LogManager.getLogger(AzureBlobContainer.class);
private static final Logger logger = LogManager.getLogger(AzureBlobContainer.class);
private final AzureBlobStore blobStore;
private final String keyPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ protected void doStop() {
protected void doClose() throws IOException {}

private static final class SuccessfulRequestTracker implements HttpPipelinePolicy {
private static final Logger logger = LogManager.getLogger(SuccessfulRequestTracker.class);
private final BiConsumer<String, URL> onSuccessfulRequest;
private final Logger logger = LogManager.getLogger(SuccessfulRequestTracker.class);

private SuccessfulRequestTracker(BiConsumer<String, URL> onSuccessfulRequest) {
this.onSuccessfulRequest = onSuccessfulRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void cancel() {
private final Condition condition;
private final Consumer<T> cleaner;
private final AtomicReference<Subscription> subscription = new AtomicReference<>();
private final Logger logger = LogManager.getLogger(CancellableRateLimitedFluxIterator.class);
private static final Logger logger = LogManager.getLogger(CancellableRateLimitedFluxIterator.class);
private volatile Throwable error;
private volatile boolean done;
private int emittedElements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class ReactorScheduledExecutorService extends AbstractExecutorService implements ScheduledExecutorService {
private final ThreadPool threadPool;
private final ExecutorService delegate;
private final Logger logger = LogManager.getLogger(ReactorScheduledExecutorService.class);
private static final Logger logger = LogManager.getLogger(ReactorScheduledExecutorService.class);

public ReactorScheduledExecutorService(ThreadPool threadPool, String executorName) {
this.threadPool = threadPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RetryingHttpInputStream extends InputStream {
public static final int MAX_SUPPRESSED_EXCEPTIONS = 10;
public static final long MAX_RANGE_VAL = Long.MAX_VALUE - 1;

private final Logger logger = LogManager.getLogger(RetryingHttpInputStream.class);
private static final Logger logger = LogManager.getLogger(RetryingHttpInputStream.class);

private final String blobName;
private final URI blobURI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class URLHttpClient implements Closeable {
public static final int MAX_ERROR_MESSAGE_BODY_SIZE = 1024;
private static final int MAX_CONNECTIONS = 50;
private final Logger logger = LogManager.getLogger(URLHttpClient.class);
private static final Logger logger = LogManager.getLogger(URLHttpClient.class);

private final CloseableHttpClient client;
private final URLHttpClientSettings httpClientSettings;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void close() throws IOException {
};
}

private void handleInvalidResponse(CloseableHttpResponse response) {
private static void handleInvalidResponse(CloseableHttpResponse response) {
int statusCode = response.getStatusLine().getStatusCode();
String errorBody = parseBodyAsString(response, MAX_ERROR_MESSAGE_BODY_SIZE);
throw new URLHttpClientException(statusCode, createErrorMessage(statusCode, errorBody));
Expand All @@ -156,7 +156,7 @@ static String createErrorMessage(int statusCode, String errorMessage) {
}
}

private String parseBodyAsString(CloseableHttpResponse response, int maxSize) {
private static String parseBodyAsString(CloseableHttpResponse response, int maxSize) {
String errorMessage = "";
InputStream bodyContent = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, minNumDataNodes = 2)
public class AwarenessAllocationIT extends ESIntegTestCase {

private final Logger logger = LogManager.getLogger(AwarenessAllocationIT.class);
private static final Logger logger = LogManager.getLogger(AwarenessAllocationIT.class);

@Override
protected int numberOfReplicas() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
package org.elasticsearch.cluster.allocation;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse;
Expand Down Expand Up @@ -66,7 +64,6 @@
@LuceneTestCase.SuppressFileSystems(value = "WindowsFS")
@ClusterScope(scope = Scope.TEST, numDataNodes = 0)
public class ClusterRerouteIT extends ESIntegTestCase {
private final Logger logger = LogManager.getLogger(ClusterRerouteIT.class);

public void testRerouteWithCommands_disableAllocationSettings() throws Exception {
Settings commonSettings = Settings.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.elasticsearch.gateway;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
Expand Down Expand Up @@ -69,8 +67,6 @@
@ClusterScope(scope = Scope.TEST, numDataNodes = 0)
public class GatewayIndexStateIT extends ESIntegTestCase {

private final Logger logger = LogManager.getLogger(GatewayIndexStateIT.class);

@Override
protected boolean addMockInternalEngine() {
// testRecoverBrokenIndexMetadata replies on the flushing on shutdown behavior which can be randomly disabled in MockInternalEngine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.elasticsearch.indices.state;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.support.ActiveShardCount;
Expand All @@ -27,8 +25,6 @@

@ESIntegTestCase.ClusterScope(minNumDataNodes = 2)
public class SimpleIndexStateIT extends ESIntegTestCase {
private final Logger logger = LogManager.getLogger(SimpleIndexStateIT.class);

public void testSimpleOpenClose() {
logger.info("--> creating test index");
createIndex("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.elasticsearch.recovery;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
Expand Down Expand Up @@ -47,7 +45,6 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;

public class RecoveryWhileUnderLoadIT extends ESIntegTestCase {
private final Logger logger = LogManager.getLogger(RecoveryWhileUnderLoadIT.class);

public static final class RetentionLeaseSyncIntervalSettingPlugin extends Plugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TransportVerifyShardBeforeCloseAction extends TransportReplicationA

public static final String NAME = CloseIndexAction.NAME + "[s]";
public static final ActionType<ReplicationResponse> TYPE = new ActionType<>(NAME, ReplicationResponse::new);
protected Logger logger = LogManager.getLogger(getClass());
private static final Logger logger = LogManager.getLogger(TransportVerifyShardBeforeCloseAction.class);

@Inject
public TransportVerifyShardBeforeCloseAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
package org.elasticsearch.action.admin.indices.readonly;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.support.ActionFilters;
Expand Down Expand Up @@ -48,7 +46,6 @@ public class TransportVerifyShardIndexBlockAction extends TransportReplicationAc

public static final String NAME = AddIndexBlockAction.NAME + "[s]";
public static final ActionType<ReplicationResponse> TYPE = new ActionType<>(NAME, ReplicationResponse::new);
protected Logger logger = LogManager.getLogger(getClass());

@Inject
public TransportVerifyShardIndexBlockAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.elasticsearch.action.admin.indices.shrink;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
Expand Down Expand Up @@ -44,7 +42,6 @@
* Main class to initiate resizing (shrink / split) an index into a new index
*/
public class TransportResizeAction extends TransportMasterNodeAction<ResizeRequest, ResizeResponse> {
private static final Logger logger = LogManager.getLogger(TransportResizeAction.class);

private final MetadataCreateIndexService createIndexService;
private final Client client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Implements the low-level details of bulk request handling
*/
public final class BulkRequestHandler {
private final Logger logger;
private static final Logger logger = LogManager.getLogger(BulkRequestHandler.class);
private final BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer;
private final BulkProcessor.Listener listener;
private final Semaphore semaphore;
Expand All @@ -36,7 +36,6 @@ public final class BulkRequestHandler {
int concurrentRequests
) {
assert concurrentRequests >= 0;
this.logger = LogManager.getLogger(getClass());
this.consumer = consumer;
this.listener = listener;
this.concurrentRequests = concurrentRequests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.function.LongConsumer;

public abstract class PreVoteCollector {
private final Logger logger = LogManager.getLogger(PreVoteCollector.class);
private static final Logger logger = LogManager.getLogger(PreVoteCollector.class);

// Tuple for simple atomic updates. null until the first call to `update()`.
protected volatile Tuple<DiscoveryNode, PreVoteResponse> state; // DiscoveryNode component is null if there is currently no known
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
public class FeatureFlag {

private final Logger logger = LogManager.getLogger(FeatureFlag.class);
private static final Logger logger = LogManager.getLogger(FeatureFlag.class);

private final String name;
private final boolean enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class HttpTracer {

private final Logger logger = LogManager.getLogger(HttpTracer.class);
private static final Logger logger = LogManager.getLogger(HttpTracer.class);

private volatile String[] tracerLogInclude;
private volatile String[] tracerLogExclude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ void sync(
}

static class SnapshotSender extends AbstractRunnable implements ActionListener<ResyncReplicationResponse> {
private final Logger logger;
private final SyncAction syncAction;
private final ResyncTask task; // to track progress
private final String primaryAllocationId;
Expand Down Expand Up @@ -270,7 +269,6 @@ static class SnapshotSender extends AbstractRunnable implements ActionListener<R
Executor executor,
ActionListener<Void> listener
) {
this.logger = PrimaryReplicaSyncer.logger;
this.syncAction = syncAction;
this.task = task;
this.shardId = shardId;
Expand Down Expand Up @@ -353,7 +351,7 @@ protected void doRun() throws Exception {
maxSeenAutoIdTimestamp,
operations.toArray(EMPTY_ARRAY)
);
logger.trace(
PrimaryReplicaSyncer.logger.trace(
"{} sending batch of [{}][{}] (total sent: [{}], skipped: [{}])",
shardId,
operations.size(),
Expand All @@ -364,7 +362,12 @@ protected void doRun() throws Exception {
firstMessage.set(false);
syncAction.sync(request, task, primaryAllocationId, primaryTerm, this);
} else if (closed.compareAndSet(false, true)) {
logger.trace("{} resync completed (total sent: [{}], skipped: [{}])", shardId, totalSentOps.get(), totalSkippedOps.get());
PrimaryReplicaSyncer.logger.trace(
"{} resync completed (total sent: [{}], skipped: [{}])",
shardId,
totalSentOps.get(),
totalSkippedOps.get()
);
listener.onResponse(null);
}
}
Expand Down
12 changes: 2 additions & 10 deletions server/src/main/java/org/elasticsearch/indices/IndicesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, lon
}
});
this.cleanInterval = INDICES_CACHE_CLEAN_INTERVAL_SETTING.get(settings);
this.cacheCleaner = new CacheCleaner(indicesFieldDataCache, indicesRequestCache, logger, threadPool, this.cleanInterval);
this.cacheCleaner = new CacheCleaner(indicesFieldDataCache, indicesRequestCache, threadPool, this.cleanInterval);
this.metaStateService = metaStateService;
this.engineFactoryProviders = engineFactoryProviders;

Expand Down Expand Up @@ -1440,22 +1440,14 @@ public AnalysisRegistry getAnalysis() {
private static final class CacheCleaner implements Runnable, Releasable {

private final IndicesFieldDataCache cache;
private final Logger logger;
private final ThreadPool threadPool;
private final TimeValue interval;
private final AtomicBoolean closed = new AtomicBoolean(false);
private final IndicesRequestCache requestCache;

CacheCleaner(
IndicesFieldDataCache cache,
IndicesRequestCache requestCache,
Logger logger,
ThreadPool threadPool,
TimeValue interval
) {
CacheCleaner(IndicesFieldDataCache cache, IndicesRequestCache requestCache, ThreadPool threadPool, TimeValue interval) {
this.cache = cache;
this.requestCache = requestCache;
this.logger = logger;
this.threadPool = threadPool;
this.interval = interval;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void close() {
}

public IndexFieldDataCache buildIndexFieldDataCache(IndexFieldDataCache.Listener listener, Index index, String fieldName) {
return new IndexFieldCache(logger, cache, index, fieldName, indicesFieldDataCacheListener, listener);
return new IndexFieldCache(cache, index, fieldName, indicesFieldDataCacheListener, listener);
}

public Cache<Key, Accountable> getCache() {
Expand Down Expand Up @@ -107,14 +107,12 @@ public long applyAsLong(Key key, Accountable ramUsage) {
* A specific cache instance for the relevant parameters of it (index, fieldNames, fieldType).
*/
static class IndexFieldCache implements IndexFieldDataCache, IndexReader.ClosedListener {
private final Logger logger;
final Index index;
final String fieldName;
private final Cache<Key, Accountable> cache;
private final Listener[] listeners;

IndexFieldCache(Logger logger, final Cache<Key, Accountable> cache, Index index, String fieldName, Listener... listeners) {
this.logger = logger;
IndexFieldCache(final Cache<Key, Accountable> cache, Index index, String fieldName, Listener... listeners) {
this.listeners = listeners;
this.index = index;
this.fieldName = fieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import static org.elasticsearch.indices.recovery.RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION;

public class ShardSnapshotsService {
private final Logger logger = LogManager.getLogger(ShardSnapshotsService.class);
private static final Logger logger = LogManager.getLogger(ShardSnapshotsService.class);

private final Client client;
private final RepositoriesService repositoriesService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class NamedComponentReader {

private Logger logger = LogManager.getLogger(NamedComponentReader.class);
private static final Logger logger = LogManager.getLogger(NamedComponentReader.class);
private static final String NAMED_COMPONENTS_FILE_NAME = "named_components.json";
/**
* a registry of known classes marked or indirectly marked (extending marked class) with @Extensible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void metadataToXContent(XContentBuilder builder, Params params) throws
* {@link Aggregator#buildAggregations} and {@link InternalAggregation#reduce}.
*/
public static class MultiBucketConsumer implements IntConsumer {
private final Logger logger = LogManager.getLogger(MultiBucketConsumer.class);
private static final Logger logger = LogManager.getLogger(MultiBucketConsumer.class);
private final int limit;
private final CircuitBreaker breaker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

public final class CompositeAggregator extends BucketsAggregator implements SizedBucketAggregator {

private final Logger logger = LogManager.getLogger(CompositeAggregator.class);
private static final Logger logger = LogManager.getLogger(CompositeAggregator.class);
private final int size;
private final List<String> sourceNames;
private final int[] reverseMuls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class TransportKeepAlive implements Closeable {
}
}

private final Logger logger = LogManager.getLogger(TransportKeepAlive.class);
private static final Logger logger = LogManager.getLogger(TransportKeepAlive.class);
private final CounterMetric successfulPings = new CounterMetric();
private final CounterMetric failedPings = new CounterMetric();
private final ConcurrentMap<TimeValue, ScheduledPing> pingIntervals = ConcurrentCollections.newConcurrentMap();
Expand Down
Loading

0 comments on commit 995b4d3

Please sign in to comment.