Skip to content

Commit

Permalink
Logging: server: clean up logging (#34593)
Browse files Browse the repository at this point in the history
Replace internal deprecated calls to `Loggers.getLogger(Class)`
with direct calls to log4j `LogManager.getLogger(Class)`
  • Loading branch information
lipsill authored and nik9000 committed Oct 25, 2018
1 parent 185c06b commit 2b652f3
Show file tree
Hide file tree
Showing 52 changed files with 116 additions and 106 deletions.
4 changes: 2 additions & 2 deletions server/src/main/java/org/elasticsearch/ExceptionsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

package org.elasticsearch;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexFormatTooNewException;
import org.apache.lucene.index.IndexFormatTooOldException;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.index.Index;
import org.elasticsearch.rest.RestStatus;
Expand All @@ -47,7 +47,7 @@

public final class ExceptionsHelper {

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

public static RuntimeException convertToRuntime(Exception e) {
if (e instanceof RuntimeException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.elasticsearch.action.admin.indices.template.put;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchGenerationException;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
Expand All @@ -34,7 +35,6 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
Expand Down Expand Up @@ -69,7 +69,7 @@
*/
public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateRequest> implements IndicesRequest, ToXContent {

private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(PutIndexTemplateRequest.class));
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(LogManager.getLogger(PutIndexTemplateRequest.class));

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.elasticsearch.action.bulk;

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.common.logging.Loggers;
import org.elasticsearch.threadpool.Scheduler;

import java.util.concurrent.CountDownLatch;
Expand All @@ -43,7 +43,7 @@ public final class BulkRequestHandler {
BulkRequestHandler(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BackoffPolicy backoffPolicy,
BulkProcessor.Listener listener, Scheduler scheduler, int concurrentRequests) {
assert concurrentRequests >= 0;
this.logger = Loggers.getLogger(getClass());
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 @@ -19,10 +19,10 @@

package org.elasticsearch.action.support;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ListenableActionFuture;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.threadpool.ThreadPool;

import java.util.ArrayList;
Expand Down Expand Up @@ -123,7 +123,7 @@ private void executeListener(final ActionListener<T> listener) {

private static final class DispatchingListenableActionFuture<T> extends PlainListenableActionFuture<T> {

private static final Logger logger = Loggers.getLogger(DispatchingListenableActionFuture.class);
private static final Logger logger = LogManager.getLogger(DispatchingListenableActionFuture.class);
private final ThreadPool threadPool;

private DispatchingListenableActionFuture(ThreadPool threadPool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void run() {

/** initialize native resources */
public static void initializeNatives(Path tmpFile, boolean mlockAll, boolean systemCallFilter, boolean ctrlHandler) {
final Logger logger = Loggers.getLogger(Bootstrap.class);
final Logger logger = LogManager.getLogger(Bootstrap.class);

// check if the user is running as root, and bail
if (Natives.definitelyRunningAsRoot()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package org.elasticsearch.bootstrap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.util.Constants;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.discovery.DiscoveryModule;
Expand Down Expand Up @@ -90,7 +90,7 @@ static void check(
final BootstrapContext context,
final boolean enforceLimits,
final List<BootstrapCheck> checks) throws NodeValidationException {
check(context, enforceLimits, checks, Loggers.getLogger(BootstrapChecks.class));
check(context, enforceLimits, checks, LogManager.getLogger(BootstrapChecks.class));
}

/**
Expand Down Expand Up @@ -417,7 +417,7 @@ public BootstrapCheckResult check(final BootstrapContext context) {

// visible for testing
long getMaxMapCount() {
return getMaxMapCount(Loggers.getLogger(BootstrapChecks.class));
return getMaxMapCount(LogManager.getLogger(BootstrapChecks.class));
}

// visible for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

package org.elasticsearch.bootstrap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.logging.Loggers;

import java.io.IOError;
import java.security.AccessController;
import java.security.PrivilegedAction;

class ElasticsearchUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final Logger logger = Loggers.getLogger(ElasticsearchUncaughtExceptionHandler.class);
private static final Logger logger = LogManager.getLogger(ElasticsearchUncaughtExceptionHandler.class);

@Override
public void uncaughtException(Thread t, Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Structure;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.Constants;
import org.elasticsearch.common.logging.Loggers;

import java.util.Arrays;
import java.util.List;
Expand All @@ -34,7 +35,7 @@
*/
final class JNACLibrary {

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

public static final int MCL_CURRENT = 1;
public static final int ENOMEM = 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import com.sun.jna.Structure;
import com.sun.jna.WString;
import com.sun.jna.win32.StdCallLibrary;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.Constants;
import org.elasticsearch.common.logging.Loggers;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -41,7 +42,7 @@
*/
final class JNAKernel32Library {

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

// Callbacks must be kept around in order to be able to be called later,
// when the Windows ConsoleCtrlHandler sends an event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.WString;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.Constants;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.monitor.jvm.JvmInfo;

import java.nio.file.Path;
Expand All @@ -40,7 +41,7 @@ class JNANatives {
/** no instantiation */
private JNANatives() {}

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

// Set to true, in case native mlockall call was successful
static boolean LOCAL_MLOCKALL = false;
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/elasticsearch/bootstrap/Natives.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.elasticsearch.bootstrap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;

import java.nio.file.Path;

Expand All @@ -32,7 +32,7 @@ final class Natives {
/** no instantiation */
private Natives() {}

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

// marker to determine if the JNA class files are available to the JVM
static final boolean JNA_AVAILABLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.ptr.PointerByReference;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.Constants;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.common.logging.Loggers;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -91,7 +92,7 @@
*/
// not an example of how to write code!!!
final class SystemCallFilter {
private static final Logger logger = Loggers.getLogger(SystemCallFilter.class);
private static final Logger logger = LogManager.getLogger(SystemCallFilter.class);

// Linux implementation, based on seccomp(2) or prctl(2) with bpf filtering

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.AbstractDiffable;
Expand All @@ -33,7 +35,6 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.ToXContent;
Expand All @@ -52,7 +53,7 @@

public class IndexTemplateMetaData extends AbstractDiffable<IndexTemplateMetaData> {

private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(IndexTemplateMetaData.class));
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(LogManager.getLogger(IndexTemplateMetaData.class));

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import com.carrotsearch.hppc.ObjectHashSet;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.lucene.util.CollectionUtil;
import org.elasticsearch.action.AliasesRequest;
import org.elasticsearch.cluster.ClusterState;
Expand All @@ -41,7 +43,6 @@
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
Expand Down Expand Up @@ -82,7 +83,7 @@

public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, ToXContentFragment {

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

public static final String ALL = "_all";

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

package org.elasticsearch.cluster.routing.allocation.command;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
Expand All @@ -32,7 +33,6 @@
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.IndexNotFoundException;
Expand Down Expand Up @@ -154,7 +154,7 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain)
discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT));
}
}
routingNodes.failShard(Loggers.getLogger(CancelAllocationCommand.class), shardRouting,
routingNodes.failShard(LogManager.getLogger(CancelAllocationCommand.class), shardRouting,
new UnassignedInfo(UnassignedInfo.Reason.REROUTE_CANCELLED, null), indexMetaData, allocation.changes());
// TODO: We don't have to remove a cancelled shard from in-sync set once we have a strict resync implementation.
allocation.removeAllocationId(shardRouting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.cluster.service;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.Assertions;
Expand All @@ -38,7 +39,6 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -553,7 +553,7 @@ public void onNodeAck(DiscoveryNode node, @Nullable Exception e) {

private static class AckCountDownListener implements Discovery.AckListener {

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

private final AckedClusterStateTaskListener ackedTaskListener;
private final CountDown countDown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.elasticsearch.common.inject.spi;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Binder;
Expand All @@ -40,7 +41,6 @@
import org.elasticsearch.common.inject.internal.ProviderMethodsModule;
import org.elasticsearch.common.inject.internal.SourceProvider;
import org.elasticsearch.common.inject.matcher.Matcher;
import org.elasticsearch.common.logging.Loggers;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand Down Expand Up @@ -338,7 +338,7 @@ public void annotatedWith(Annotation annotation) {
return builder;
}

private static Logger logger = Loggers.getLogger(Elements.class);
private static Logger logger = LogManager.getLogger(Elements.class);

protected Object getSource() {
Object ret;
Expand Down
Loading

0 comments on commit 2b652f3

Please sign in to comment.