You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2022/05/09 06:48:56 UTC

[unomi] 01/01: UNOMI-567 : clean up logs - backport of #416

This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a commit to branch backport-filter-unomi-logs
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 02e5ffdb8e66bfec9599899d1306b6ead3d9c14d
Author: David Griffon <dg...@jahia.com>
AuthorDate: Mon May 9 08:48:44 2022 +0200

    UNOMI-567 : clean up logs - backport of #416
---
 .../elasticsearch/ElasticSearchPersistenceServiceImpl.java | 14 ++++++++++++--
 .../src/main/resources/OSGI-INF/blueprint/blueprint.xml    |  1 +
 .../org.apache.unomi.persistence.elasticsearch.cfg         |  3 +++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 4ef4dcda7..5d6066e99 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -27,6 +27,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.conn.ssl.NoopHostnameVerifier;
 import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.log4j.Level;
 import org.apache.lucene.search.TotalHits;
 import org.apache.unomi.api.Item;
 import org.apache.unomi.api.PartialList;
@@ -120,7 +121,6 @@ import javax.net.ssl.X509TrustManager;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.lang.reflect.Field;
 import java.net.URL;
 import java.security.KeyManagementException;
 import java.security.NoSuchAlgorithmException;
@@ -130,7 +130,6 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 
@@ -202,6 +201,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
     private String itemClassesToCache;
     private boolean useBatchingForSave = false;
     private boolean useBatchingForUpdate = true;
+    private boolean errorLogLevelRestClient = true;
     private boolean alwaysOverwrite = true;
     private boolean aggQueryThrowOnMissingDocs = false;
     private Integer aggQueryMaxResponseSizeHttp = null;
@@ -396,9 +396,19 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
         this.alwaysOverwrite = alwaysOverwrite;
     }
 
+    public void setErrorLogLevelRestClient(boolean errorLogLevelRestClient) {
+        this.errorLogLevelRestClient = errorLogLevelRestClient;
+    }
 
     public void start() throws Exception {
 
+        // Work around to avoid ES Logs regarding the deprecated [ignore_throttled] parameter
+        if (errorLogLevelRestClient) {
+            org.apache.log4j.Logger.getLogger("org.elasticsearch.client.RestClient").setLevel(Level.ERROR);
+        } else {
+            org.apache.log4j.Logger.getLogger("org.elasticsearch.client.RestClient").setLevel(Level.INFO);
+        }
+
         // on startup
         new InClassLoaderExecute<Object>(null, null, this.bundleContext, this.fatalIllegalStateErrors, throwExceptions) {
             public Object execute(Object... args) throws Exception {
diff --git a/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index f628a8c23..c5ba7b7d3 100644
--- a/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -146,6 +146,7 @@
         <property name="sslTrustAllCertificates" value="${es.sslTrustAllCertificates}" />
         <property name="throwExceptions" value="${es.throwExceptions}" />
         <property name="alwaysOverwrite" value="${es.alwaysOverwrite}" />
+        <property name="errorLogLevelRestClient" value="${es.errorLogLevelRestClient}" />
     </bean>
 
     <!-- We use a listener here because using the list directly for listening to proxies coming from the same bundle didn't seem to work -->
diff --git a/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg b/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg
index 71c2577b7..75d84a470 100644
--- a/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg
+++ b/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg
@@ -81,3 +81,6 @@ throwExceptions=${org.apache.unomi.elasticsearch.throwExceptions:-false}
 
 alwaysOverwrite=${org.apache.unomi.elasticsearch.alwaysOverwrite:-true}
 useBatchingForUpdate=${org.apache.unomi.elasticsearch.useBatchingForUpdate:-true}
+
+# ES logging
+errorLogLevelRestClient=${org.apache.unomi.elasticsearch.errorLogLevelRestClient:-true}