Skip to content

Commit d6ebbc4

Browse files
lipsillkcm
authored andcommitted
Logging: tests: clean up logging (#34606)
Replace internal deprecated calls to `Loggers.getLogger(Class)` with direct calls to log4j `LogManager.getLogger(Class)`
1 parent c61a542 commit d6ebbc4

File tree

68 files changed

+151
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+151
-133
lines changed

server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
*/
1919
package org.elasticsearch.action.search;
2020

21+
import org.apache.logging.log4j.LogManager;
2122
import org.apache.logging.log4j.Logger;
2223
import org.elasticsearch.action.OriginalIndices;
2324
import org.elasticsearch.common.Nullable;
24-
import org.elasticsearch.common.logging.Loggers;
2525
import org.elasticsearch.search.SearchShardTarget;
2626
import org.elasticsearch.search.internal.InternalSearchResponse;
2727
import org.elasticsearch.search.internal.ShardSearchTransportRequest;
@@ -40,7 +40,7 @@
4040
* SearchPhaseContext for tests
4141
*/
4242
public final class MockSearchPhaseContext implements SearchPhaseContext {
43-
private static final Logger logger = Loggers.getLogger(MockSearchPhaseContext.class);
43+
private static final Logger logger = LogManager.getLogger(MockSearchPhaseContext.class);
4444
public AtomicReference<Throwable> phaseFailure = new AtomicReference<>();
4545
final int numShards;
4646
final AtomicInteger numSuccess;

server/src/test/java/org/elasticsearch/cluster/allocation/AwarenessAllocationIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.cluster.allocation;
2121

2222
import com.carrotsearch.hppc.ObjectIntHashMap;
23+
24+
import org.apache.logging.log4j.LogManager;
2325
import org.apache.logging.log4j.Logger;
2426
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
2527
import org.elasticsearch.cluster.ClusterState;
@@ -28,7 +30,6 @@
2830
import org.elasticsearch.cluster.routing.ShardRouting;
2931
import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
3032
import org.elasticsearch.common.Priority;
31-
import org.elasticsearch.common.logging.Loggers;
3233
import org.elasticsearch.common.settings.Settings;
3334
import org.elasticsearch.discovery.zen.ZenDiscovery;
3435
import org.elasticsearch.test.ESIntegTestCase;
@@ -43,7 +44,7 @@
4344
@ClusterScope(scope= ESIntegTestCase.Scope.TEST, numDataNodes =0, minNumDataNodes = 2)
4445
public class AwarenessAllocationIT extends ESIntegTestCase {
4546

46-
private final Logger logger = Loggers.getLogger(AwarenessAllocationIT.class);
47+
private final Logger logger = LogManager.getLogger(AwarenessAllocationIT.class);
4748

4849
@Override
4950
protected int numberOfReplicas() {

server/src/test/java/org/elasticsearch/cluster/allocation/ClusterRerouteIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.cluster.allocation;
2121

2222
import org.apache.logging.log4j.Level;
23+
import org.apache.logging.log4j.LogManager;
2324
import org.apache.logging.log4j.Logger;
2425
import org.elasticsearch.core.internal.io.IOUtils;
2526
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
@@ -74,7 +75,7 @@
7475

7576
@ClusterScope(scope = Scope.TEST, numDataNodes = 0)
7677
public class ClusterRerouteIT extends ESIntegTestCase {
77-
private final Logger logger = Loggers.getLogger(ClusterRerouteIT.class);
78+
private final Logger logger = LogManager.getLogger(ClusterRerouteIT.class);
7879

7980
public void testRerouteWithCommands_disableAllocationSettings() throws Exception {
8081
Settings commonSettings = Settings.builder()
@@ -334,7 +335,7 @@ public void testMessageLogging() throws Exception{
334335
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1))
335336
.execute().actionGet();
336337

337-
Logger actionLogger = Loggers.getLogger(TransportClusterRerouteAction.class);
338+
Logger actionLogger = LogManager.getLogger(TransportClusterRerouteAction.class);
338339

339340
MockLogAppender dryRunMockLog = new MockLogAppender();
340341
dryRunMockLog.start();

server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.cluster.ClusterState;
2425
import org.elasticsearch.cluster.health.ClusterHealthStatus;
@@ -29,7 +30,6 @@
2930
import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider;
3031
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
3132
import org.elasticsearch.common.Strings;
32-
import org.elasticsearch.common.logging.Loggers;
3333
import org.elasticsearch.common.settings.Setting;
3434
import org.elasticsearch.common.settings.Settings;
3535
import org.elasticsearch.index.query.QueryBuilders;
@@ -46,7 +46,7 @@
4646
@ClusterScope(scope= Scope.TEST, numDataNodes =0)
4747
public class FilteringAllocationIT extends ESIntegTestCase {
4848

49-
private final Logger logger = Loggers.getLogger(FilteringAllocationIT.class);
49+
private final Logger logger = LogManager.getLogger(FilteringAllocationIT.class);
5050

5151
public void testDecommissionNodeNoReplicas() throws Exception {
5252
logger.info("--> starting 2 nodes");

server/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.cluster.routing.allocation;
2121

2222
import com.carrotsearch.hppc.cursors.ObjectCursor;
23+
24+
import org.apache.logging.log4j.LogManager;
2325
import org.apache.logging.log4j.Logger;
2426
import org.elasticsearch.Version;
2527
import org.elasticsearch.cluster.ClusterState;
@@ -32,7 +34,6 @@
3234
import org.elasticsearch.cluster.routing.RoutingNodes;
3335
import org.elasticsearch.cluster.routing.RoutingTable;
3436
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
35-
import org.elasticsearch.common.logging.Loggers;
3637
import org.elasticsearch.common.settings.Settings;
3738
import org.elasticsearch.common.util.CollectionUtils;
3839
import org.hamcrest.Matcher;
@@ -47,7 +48,7 @@
4748
import static org.hamcrest.Matchers.not;
4849

4950
public class AddIncrementallyTests extends ESAllocationTestCase {
50-
private final Logger logger = Loggers.getLogger(AddIncrementallyTests.class);
51+
private final Logger logger = LogManager.getLogger(AddIncrementallyTests.class);
5152

5253
public void testAddNodesAndIndices() {
5354
Settings.Builder settings = Settings.builder();

server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.routing.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.Version;
2425
import org.elasticsearch.cluster.ClusterInfo;
@@ -44,7 +45,6 @@
4445
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
4546
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
4647
import org.elasticsearch.common.io.stream.StreamInput;
47-
import org.elasticsearch.common.logging.Loggers;
4848
import org.elasticsearch.common.network.NetworkModule;
4949
import org.elasticsearch.common.settings.Settings;
5050
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@@ -70,7 +70,7 @@
7070
import static org.hamcrest.Matchers.nullValue;
7171

7272
public class AllocationCommandsTests extends ESAllocationTestCase {
73-
private final Logger logger = Loggers.getLogger(AllocationCommandsTests.class);
73+
private final Logger logger = LogManager.getLogger(AllocationCommandsTests.class);
7474

7575
public void testMoveShardCommand() {
7676
AllocationService allocation = createAllocationService(Settings.builder().put("cluster.routing.allocation.node_concurrent_recoveries", 10).build());

server/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.routing.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.Version;
2425
import org.elasticsearch.cluster.ClusterState;
@@ -34,7 +35,6 @@
3435
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
3536
import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
3637
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
37-
import org.elasticsearch.common.logging.Loggers;
3838
import org.elasticsearch.common.settings.Settings;
3939

4040
import java.util.HashMap;
@@ -51,7 +51,7 @@
5151

5252
public class AwarenessAllocationTests extends ESAllocationTestCase {
5353

54-
private final Logger logger = Loggers.getLogger(AwarenessAllocationTests.class);
54+
private final Logger logger = LogManager.getLogger(AwarenessAllocationTests.class);
5555

5656
public void testMoveShardOnceNewNodeWithAttributeAdded1() {
5757
AllocationService strategy = createAllocationService(Settings.builder()

server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.cluster.routing.allocation;
2121

2222
import com.carrotsearch.hppc.cursors.ObjectCursor;
23+
24+
import org.apache.logging.log4j.LogManager;
2325
import org.apache.logging.log4j.Logger;
2426
import org.apache.lucene.util.ArrayUtil;
2527
import org.elasticsearch.Version;
@@ -38,7 +40,6 @@
3840
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
3941
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
4042
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
41-
import org.elasticsearch.common.logging.Loggers;
4243
import org.elasticsearch.common.settings.ClusterSettings;
4344
import org.elasticsearch.common.settings.Settings;
4445
import org.elasticsearch.gateway.GatewayAllocator;
@@ -52,7 +53,7 @@
5253

5354
public class BalanceConfigurationTests extends ESAllocationTestCase {
5455

55-
private final Logger logger = Loggers.getLogger(BalanceConfigurationTests.class);
56+
private final Logger logger = LogManager.getLogger(BalanceConfigurationTests.class);
5657
// TODO maybe we can randomize these numbers somehow
5758
final int numberOfNodes = 25;
5859
final int numberOfIndices = 12;

server/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.routing.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.Version;
2425
import org.elasticsearch.cluster.ClusterState;
@@ -31,7 +32,6 @@
3132
import org.elasticsearch.cluster.routing.ShardRouting;
3233
import org.elasticsearch.cluster.routing.UnassignedInfo;
3334
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
34-
import org.elasticsearch.common.logging.Loggers;
3535
import org.elasticsearch.common.settings.Settings;
3636
import org.elasticsearch.test.gateway.TestGatewayAllocator;
3737

@@ -46,7 +46,7 @@
4646
import static org.hamcrest.Matchers.not;
4747

4848
public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
49-
private final Logger logger = Loggers.getLogger(ClusterRebalanceRoutingTests.class);
49+
private final Logger logger = LogManager.getLogger(ClusterRebalanceRoutingTests.class);
5050

5151
public void testAlways() {
5252
AllocationService strategy = createAllocationService(Settings.builder().put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(),

server/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.routing.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.Version;
2425
import org.elasticsearch.cluster.ClusterState;
@@ -28,7 +29,6 @@
2829
import org.elasticsearch.cluster.node.DiscoveryNodes;
2930
import org.elasticsearch.cluster.routing.RoutingNodes;
3031
import org.elasticsearch.cluster.routing.RoutingTable;
31-
import org.elasticsearch.common.logging.Loggers;
3232
import org.elasticsearch.common.settings.Settings;
3333

3434
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@@ -39,7 +39,7 @@
3939
import static org.hamcrest.Matchers.nullValue;
4040

4141
public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
42-
private final Logger logger = Loggers.getLogger(ConcurrentRebalanceRoutingTests.class);
42+
private final Logger logger = LogManager.getLogger(ConcurrentRebalanceRoutingTests.class);
4343

4444
public void testClusterConcurrentRebalance() {
4545
AllocationService strategy = createAllocationService(Settings.builder()

server/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.routing.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.Version;
2425
import org.elasticsearch.cluster.ClusterState;
@@ -30,7 +31,6 @@
3031
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
3132
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
3233
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
33-
import org.elasticsearch.common.logging.Loggers;
3434
import org.elasticsearch.common.settings.Settings;
3535

3636
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@@ -40,7 +40,7 @@
4040
import static org.hamcrest.Matchers.not;
4141

4242
public class DeadNodesAllocationTests extends ESAllocationTestCase {
43-
private final Logger logger = Loggers.getLogger(DeadNodesAllocationTests.class);
43+
private final Logger logger = LogManager.getLogger(DeadNodesAllocationTests.class);
4444

4545
public void testSimpleDeadNodeOnStartedPrimaryShard() {
4646
AllocationService allocation = createAllocationService(Settings.builder()

server/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.routing.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.Version;
2425
import org.elasticsearch.cluster.ClusterState;
@@ -29,7 +30,6 @@
2930
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
3031
import org.elasticsearch.cluster.routing.RoutingNodes;
3132
import org.elasticsearch.cluster.routing.RoutingTable;
32-
import org.elasticsearch.common.logging.Loggers;
3333
import org.elasticsearch.common.settings.Settings;
3434

3535
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@@ -38,7 +38,7 @@
3838
import static org.hamcrest.Matchers.not;
3939

4040
public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTestCase {
41-
private final Logger logger = Loggers.getLogger(ElectReplicaAsPrimaryDuringRelocationTests.class);
41+
private final Logger logger = LogManager.getLogger(ElectReplicaAsPrimaryDuringRelocationTests.class);
4242

4343
public void testElectReplicaAsPrimaryDuringRelocation() {
4444
AllocationService strategy = createAllocationService(Settings.builder().put("cluster.routing.allocation.node_concurrent_recoveries", 10).build());

server/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.routing.allocation;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.apache.logging.log4j.Logger;
2324
import org.elasticsearch.Version;
2425
import org.elasticsearch.cluster.ClusterInfo;
@@ -33,15 +34,14 @@
3334
import org.elasticsearch.cluster.routing.ShardRoutingState;
3435
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
3536
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
36-
import org.elasticsearch.common.logging.Loggers;
3737
import org.elasticsearch.common.settings.Settings;
3838

3939
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
4040
import static org.hamcrest.Matchers.equalTo;
4141
import static org.hamcrest.Matchers.not;
4242

4343
public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
44-
private final Logger logger = Loggers.getLogger(ExpectedShardSizeAllocationTests.class);
44+
private final Logger logger = LogManager.getLogger(ExpectedShardSizeAllocationTests.class);
4545

4646
public void testInitializingHasExpectedSize() {
4747
final long byteSize = randomIntBetween(0, Integer.MAX_VALUE);

server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.carrotsearch.hppc.cursors.ObjectCursor;
2323

24+
import org.apache.logging.log4j.LogManager;
2425
import org.apache.logging.log4j.Logger;
2526
import org.elasticsearch.Version;
2627
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest;
@@ -38,7 +39,6 @@
3839
import org.elasticsearch.cluster.routing.RoutingTable;
3940
import org.elasticsearch.cluster.routing.ShardRouting;
4041
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
41-
import org.elasticsearch.common.logging.Loggers;
4242
import org.elasticsearch.common.settings.Settings;
4343
import org.elasticsearch.common.util.set.Sets;
4444
import org.elasticsearch.indices.cluster.ClusterStateChanges;
@@ -63,7 +63,7 @@
6363
import static org.hamcrest.Matchers.equalTo;
6464

6565
public class FailedNodeRoutingTests extends ESAllocationTestCase {
66-
private final Logger logger = Loggers.getLogger(FailedNodeRoutingTests.class);
66+
private final Logger logger = LogManager.getLogger(FailedNodeRoutingTests.class);
6767

6868
public void testSimpleFailedNodeTest() {
6969
AllocationService strategy = createAllocationService(Settings.builder().put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(),

server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.cluster.routing.allocation;
2121

2222
import com.carrotsearch.hppc.cursors.ObjectCursor;
23+
24+
import org.apache.logging.log4j.LogManager;
2325
import org.apache.logging.log4j.Logger;
2426
import org.elasticsearch.Version;
2527
import org.elasticsearch.cluster.ClusterState;
@@ -34,7 +36,6 @@
3436
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
3537
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
3638
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
37-
import org.elasticsearch.common.logging.Loggers;
3839
import org.elasticsearch.common.settings.Settings;
3940
import org.elasticsearch.index.shard.ShardId;
4041
import org.elasticsearch.test.VersionUtils;
@@ -56,7 +57,7 @@
5657
import static org.hamcrest.Matchers.nullValue;
5758

5859
public class FailedShardsRoutingTests extends ESAllocationTestCase {
59-
private final Logger logger = Loggers.getLogger(FailedShardsRoutingTests.class);
60+
private final Logger logger = LogManager.getLogger(FailedShardsRoutingTests.class);
6061

6162
public void testFailedShardPrimaryRelocatingToAndFrom() {
6263
AllocationService allocation = createAllocationService(Settings.builder()

0 commit comments

Comments
 (0)