Skip to content

Commit

Permalink
Remove remaining single arg ParameterizedMessages (#86715)
Browse files Browse the repository at this point in the history
This commit removes the remaining ParameterizedMessages that take a
single argument, this time where the argument contains method calls.
This was again done almost entirely through find/replace with regex in
IntelliJ.

relates #86549
  • Loading branch information
rjernst authored May 12, 2022
1 parent 11886d7 commit 12b98b3
Show file tree
Hide file tree
Showing 107 changed files with 185 additions and 371 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ If you wish to use placeholders and an exception at the same time, construct a
You can also use a `Supplier<ParameterizedMessage>` to avoid constructing
expensive messages that will usually be discarded:

logger.debug(() -> new ParameterizedMessage("rarely seen output [{}]", expensiveMethod()));
logger.debug(() -> "rarely seen output [" + expensiveMethod() + "]");

Logging is an important behaviour of the system and sometimes deserves its own
unit tests, especially if there is complex logic for computing what is logged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.elasticsearch.reindex;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.DocWriteResponse;
Expand Down Expand Up @@ -580,7 +579,7 @@ public void onFailure(Exception e) {
* @param failure if non null then the request failed catastrophically with this exception
*/
protected void finishHim(Exception failure) {
logger.debug(() -> new ParameterizedMessage("[{}]: finishing with a catastrophic failure", task.getId()), failure);
logger.debug(() -> "[" + task.getId() + "]: finishing with a catastrophic failure", failure);
finishHim(failure, emptyList(), emptyList(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpVersion;

import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.network.NetworkAddress;
Expand Down Expand Up @@ -158,10 +157,7 @@ public void dispatchRequest(RestRequest request, RestChannel channel, ThreadCont

@Override
public void dispatchBadRequest(RestChannel channel, ThreadContext threadContext, Throwable cause) {
logger.error(
new ParameterizedMessage("--> Unexpected bad request [{}]", FakeRestRequest.requestToString(channel.request())),
cause
);
logger.error(() -> "--> Unexpected bad request [" + FakeRestRequest.requestToString(channel.request()) + "]", cause);
throw new AssertionError();
}
};
Expand Down Expand Up @@ -337,10 +333,7 @@ public void dispatchRequest(final RestRequest request, final RestChannel channel

@Override
public void dispatchBadRequest(final RestChannel channel, final ThreadContext threadContext, final Throwable cause) {
logger.error(
new ParameterizedMessage("--> Unexpected bad request [{}]", FakeRestRequest.requestToString(channel.request())),
cause
);
logger.error(() -> "--> Unexpected bad request [" + FakeRestRequest.requestToString(channel.request()) + "]", cause);
throw new AssertionError();
}

Expand Down Expand Up @@ -402,10 +395,7 @@ public void dispatchRequest(final RestRequest request, final RestChannel channel

@Override
public void dispatchBadRequest(final RestChannel channel, final ThreadContext threadContext, final Throwable cause) {
logger.error(
new ParameterizedMessage("--> Unexpected bad request [{}]", FakeRestRequest.requestToString(channel.request())),
cause
);
logger.error(() -> "--> Unexpected bad request [" + FakeRestRequest.requestToString(channel.request()) + "]", cause);
throw new AssertionError();
}

Expand Down Expand Up @@ -473,10 +463,7 @@ public void dispatchRequest(final RestRequest request, final RestChannel channel

@Override
public void dispatchBadRequest(final RestChannel channel, final ThreadContext threadContext, final Throwable cause) {
logger.error(
new ParameterizedMessage("--> Unexpected bad request [{}]", FakeRestRequest.requestToString(channel.request())),
cause
);
logger.error(() -> "--> Unexpected bad request [" + FakeRestRequest.requestToString(channel.request()) + "]", cause);
throw new AssertionError("Should not have received a dispatched request");
}

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

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.cloud.gce.util.Access;
import org.elasticsearch.common.settings.Setting;
Expand Down Expand Up @@ -85,7 +84,7 @@ public Collection<Instance> instances() {
return zoneInstances;
});
} catch (IOException e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("Problem fetching instance list for zone {}", zoneId), e);
logger.warn((Supplier<?>) () -> "Problem fetching instance list for zone " + zoneId, e);
logger.debug("Full exception:", e);
// assist type inference
return Collections.<Instance>emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.elasticsearch.search.aggregations.metrics;

import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -221,7 +220,7 @@ private void assertShardExecutionState(SearchResponse response, int expectedFail
ShardSearchFailure[] failures = response.getShardFailures();
if (failures.length != expectedFailures) {
for (ShardSearchFailure failure : failures) {
logger.error(new ParameterizedMessage("Shard Failure: {}", failure), failure.getCause());
logger.error(() -> "Shard Failure: " + failure, failure.getCause());
}
fail("Unexpected shard failures!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.DestructiveOperations;
Expand All @@ -31,6 +30,7 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;

import java.util.Arrays;
import java.util.Collections;

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ protected void masterOperation(
request.timeout()
).masterNodeTimeout(request.masterNodeTimeout()).waitForActiveShards(request.waitForActiveShards()).indices(concreteIndices);
indexStateService.closeIndices(closeRequest, listener.delegateResponse((delegatedListener, t) -> {
logger.debug(() -> new ParameterizedMessage("failed to close indices [{}]", (Object) concreteIndices), t);
logger.debug(() -> "failed to close indices [" + Arrays.toString(concreteIndices) + "]", t);
delegatedListener.onFailure(t);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.RequestValidators;
import org.elasticsearch.action.support.ActionFilters;
Expand Down Expand Up @@ -112,7 +111,7 @@ protected void masterOperation(

performMappingUpdate(concreteIndices, request, listener, metadataMappingService);
} catch (IndexNotFoundException ex) {
logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}]", Arrays.asList(request.indices())), ex);
logger.debug(() -> "failed to put mappings on indices [" + Arrays.asList(request.indices() + "]"), ex);
throw ex;
}
}
Expand Down Expand Up @@ -148,7 +147,7 @@ static void performMappingUpdate(
MetadataMappingService metadataMappingService
) {
final ActionListener<AcknowledgedResponse> wrappedListener = listener.delegateResponse((l, e) -> {
logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}]", Arrays.asList(concreteIndices)), e);
logger.debug(() -> "failed to put mappings on indices [" + Arrays.asList(concreteIndices) + "]", e);
l.onFailure(e);
});
final PutMappingClusterStateUpdateRequest updateRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.DestructiveOperations;
Expand All @@ -28,6 +27,8 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;

import java.util.Arrays;

/**
* Open index action
*/
Expand Down Expand Up @@ -101,7 +102,7 @@ public void onResponse(ShardsAcknowledgedResponse response) {

@Override
public void onFailure(Exception t) {
logger.debug(() -> new ParameterizedMessage("failed to open indices [{}]", (Object) concreteIndices), t);
logger.debug(() -> "failed to open indices [" + Arrays.toString(concreteIndices) + "]", t);
listener.onFailure(t);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.DestructiveOperations;
Expand All @@ -27,6 +26,7 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;

import java.util.Arrays;
import java.util.Collections;

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ protected void masterOperation(
task.getId()
).ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()).indices(concreteIndices);
indexStateService.addIndexBlock(addBlockRequest, listener.delegateResponse((delegatedListener, t) -> {
logger.debug(() -> new ParameterizedMessage("failed to mark indices as readonly [{}]", (Object) concreteIndices), t);
logger.debug(() -> "failed to mark indices as readonly [" + Arrays.toString(concreteIndices) + "]", t);
delegatedListener.onFailure(t);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
Expand All @@ -33,6 +32,7 @@
import org.elasticsearch.transport.TransportService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -129,7 +129,7 @@ protected void masterOperation(
.masterNodeTimeout(request.masterNodeTimeout());

updateSettingsService.updateSettings(clusterStateUpdateRequest, listener.delegateResponse((l, e) -> {
logger.debug(() -> new ParameterizedMessage("failed to update settings on indices [{}]", (Object) concreteIndices), e);
logger.debug(() -> "failed to update settings on indices [" + Arrays.toString(concreteIndices) + "]", e);
l.onFailure(e);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
Expand Down Expand Up @@ -78,7 +77,7 @@ public void onResponse(AcknowledgedResponse response) {

@Override
public void onFailure(Exception e) {
logger.debug(() -> new ParameterizedMessage("failed to delete templates [{}]", request.name()), e);
logger.debug(() -> "failed to delete templates [" + request.name() + "]", e);
listener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
Expand Down Expand Up @@ -102,7 +101,7 @@ public void onResponse(AcknowledgedResponse response) {

@Override
public void onFailure(Exception e) {
logger.debug(() -> new ParameterizedMessage("failed to put template [{}]", request.name()), e);
logger.debug(() -> "failed to put template [" + request.name() + "]", e);
listener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPha
Throwable cause = shardSearchFailures.length == 0
? null
: ElasticsearchException.guessRootCauses(shardSearchFailures[0].getCause())[0];
logger.debug(() -> new ParameterizedMessage("All shards failed for phase: [{}]", currentPhase.getName()), cause);
logger.debug(() -> "All shards failed for phase: [" + currentPhase.getName() + "]", cause);
onPhaseFailure(currentPhase, "all shards failed", cause);
} else {
Boolean allowPartialResults = request.allowPartialSearchResults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.elasticsearch.action.search;

import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.search.SearchPhaseResult;
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.dfs.AggregatedDfs;
Expand Down Expand Up @@ -96,10 +95,7 @@ protected void innerOnResponse(QuerySearchResult response) {
public void onFailure(Exception exception) {
try {
context.getLogger()
.debug(
() -> new ParameterizedMessage("[{}] Failed to execute query phase", querySearchRequest.contextId()),
exception
);
.debug(() -> "[" + querySearchRequest.contextId() + "] Failed to execute query phase", exception);
progressListener.notifyQueryFailure(shardIndex, shardTarget, exception);
counter.onFailure(shardIndex, shardTarget, exception);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package org.elasticsearch.action.search;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.search.ScoreDoc;
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
Expand Down Expand Up @@ -219,10 +218,7 @@ public void innerOnResponse(FetchSearchResult result) {
@Override
public void onFailure(Exception e) {
try {
logger.debug(
() -> new ParameterizedMessage("[{}] Failed to execute fetch phase", fetchSearchRequest.contextId()),
e
);
logger.debug(() -> "[" + fetchSearchRequest.contextId() + "] Failed to execute fetch phase", e);
progressListener.notifyFetchFailure(shardIndex, shardTarget, e);
counter.onFailure(shardIndex, shardTarget, e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.search.TotalHits;
import org.elasticsearch.action.search.SearchResponse.Clusters;
import org.elasticsearch.cluster.routing.GroupShardsIterator;
Expand Down Expand Up @@ -109,21 +108,15 @@ final void notifyQueryResult(int shardIndex) {
try {
onQueryResult(shardIndex);
} catch (Exception e) {
logger.warn(
() -> new ParameterizedMessage("[{}] Failed to execute progress listener on query result", shards.get(shardIndex)),
e
);
logger.warn(() -> "[" + shards.get(shardIndex) + "] Failed to execute progress listener on query result", e);
}
}

final void notifyQueryFailure(int shardIndex, SearchShardTarget shardTarget, Exception exc) {
try {
onQueryFailure(shardIndex, shardTarget, exc);
} catch (Exception e) {
logger.warn(
() -> new ParameterizedMessage("[{}] Failed to execute progress listener on query failure", shards.get(shardIndex)),
e
);
logger.warn(() -> "[" + shards.get(shardIndex) + "] Failed to execute progress listener on query failure", e);
}
}

Expand All @@ -147,21 +140,15 @@ final void notifyFetchResult(int shardIndex) {
try {
onFetchResult(shardIndex);
} catch (Exception e) {
logger.warn(
() -> new ParameterizedMessage("[{}] Failed to execute progress listener on fetch result", shards.get(shardIndex)),
e
);
logger.warn(() -> "[" + shards.get(shardIndex) + "] Failed to execute progress listener on fetch result", e);
}
}

final void notifyFetchFailure(int shardIndex, SearchShardTarget shardTarget, Exception exc) {
try {
onFetchFailure(shardIndex, shardTarget, exc);
} catch (Exception e) {
logger.warn(
() -> new ParameterizedMessage("[{}] Failed to execute progress listener on fetch failure", shards.get(shardIndex)),
e
);
logger.warn(() -> "[" + shards.get(shardIndex) + "] Failed to execute progress listener on fetch failure", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public boolean isForceExecution() {
public void onFailure(Exception e) {
e.addSuppressed(failure);
assert false : e;
logger.error(new ParameterizedMessage("unexpected failure while failing primary [{}]", primary.routingEntry()), e);
logger.error(() -> "unexpected failure while failing primary [" + primary.routingEntry() + "]", e);
finishAsFailed(
new RetryOnPrimaryException(
primary.routingEntry().shardId(),
Expand Down
Loading

0 comments on commit 12b98b3

Please sign in to comment.