瀏覽代碼

Replace log4j-1.2 with log4j2 API (#87225)

Some of the logging usages are incorrectly using log4j v 1.2
instead of log4j2-api.
This commit fixes this.
Przemyslaw Gomulka 3 年之前
父節點
當前提交
4d4c773ce9

+ 8 - 9
modules/repository-url/src/main/java/org/elasticsearch/common/blobstore/url/http/RetryingHttpInputStream.java

@@ -8,9 +8,8 @@
 
 package org.elasticsearch.common.blobstore.url.http;
 
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.logging.log4j.message.ParameterizedMessage;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.common.util.Maps;
 import org.elasticsearch.core.IOUtils;
 import org.elasticsearch.rest.RestStatus;
@@ -26,9 +25,9 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
-import java.util.function.Supplier;
 
 import static org.elasticsearch.common.blobstore.url.http.URLHttpClient.MAX_ERROR_MESSAGE_BODY_SIZE;
+import static org.elasticsearch.core.Strings.format;
 
 class RetryingHttpInputStream extends InputStream {
     public static final int MAX_SUPPRESSED_EXCEPTIONS = 10;
@@ -149,8 +148,8 @@ class RetryingHttpInputStream extends InputStream {
     private void maybeThrow(IOException e) throws IOException {
         if (retryCount >= maxRetries || e instanceof NoSuchFileException) {
             logger.debug(
-                new ParameterizedMessage(
-                    "failed reading [{}] at offset [{}], retry [{}] of [{}], giving up",
+                () -> format(
+                    "failed reading [%s] at offset [%s], retry [%s] of [%s], giving up",
                     blobURI,
                     start + totalBytesRead,
                     retryCount,
@@ -162,8 +161,8 @@ class RetryingHttpInputStream extends InputStream {
         }
 
         logger.debug(
-            new ParameterizedMessage(
-                "failed reading [{}] at offset [{}], retry [{}] of [{}], retrying",
+            () -> format(
+                "failed reading [%s] at offset [%s], retry [%s] of [%s], retrying",
                 blobURI,
                 start + totalBytesRead,
                 retryCount,
@@ -293,7 +292,7 @@ class RetryingHttpInputStream extends InputStream {
             return contentLength == null ? 0 : Long.parseLong(contentLength);
 
         } catch (Exception e) {
-            logger.debug((Supplier<?>) () -> "Unable to parse response headers while reading [" + blobURI + "]", e);
+            logger.debug(() -> "Unable to parse response headers while reading [" + blobURI + "]", e);
             return MAX_RANGE_VAL;
         }
     }

+ 2 - 2
modules/repository-url/src/main/java/org/elasticsearch/common/blobstore/url/http/URLHttpClient.java

@@ -19,8 +19,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.ssl.SSLContexts;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.common.io.Streams;
 import org.elasticsearch.core.IOUtils;
 import org.elasticsearch.core.Nullable;

+ 2 - 2
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlLifeCycleService.java

@@ -6,8 +6,8 @@
  */
 package org.elasticsearch.xpack.ml;
 
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.component.LifecycleListener;

+ 2 - 2
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgrader.java

@@ -7,8 +7,8 @@
 
 package org.elasticsearch.xpack.searchablesnapshots.upgrade;
 
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.Version;
 import org.elasticsearch.cluster.ClusterChangedEvent;
 import org.elasticsearch.cluster.ClusterState;

+ 2 - 2
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/InitialNodeSecurityAutoConfiguration.java

@@ -7,8 +7,8 @@
 
 package org.elasticsearch.xpack.security;
 
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.elasticsearch.Version;
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.action.bulk.BackoffPolicy;