You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2022/01/15 16:09:37 UTC

[incubator-ponymail-foal] branch master updated: Allow override of ES logging

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

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 6aece15  Allow override of ES logging
6aece15 is described below

commit 6aece15f483f49e027b97644fb109414e3c62e67
Author: Sebb <se...@apache.org>
AuthorDate: Sat Jan 15 16:09:26 2022 +0000

    Allow override of ES logging
---
 tools/import-mbox.py     | 19 ++++++++++++++++++-
 tools/plugins/elastic.py | 21 ++++++++++++---------
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/tools/import-mbox.py b/tools/import-mbox.py
index 11ba16a..f74b78b 100755
--- a/tools/import-mbox.py
+++ b/tools/import-mbox.py
@@ -528,6 +528,20 @@ parser.add_argument(
     help="Show details of generated id (for use with --dry)",
 )
 parser.add_argument(
+    "--logger_level",
+    dest="logger_level",
+    type=str,
+    nargs=1,
+    help="Set 'elasticsearch' logging level (e.g. 'INFO')",
+)
+parser.add_argument(
+    "--trace_level",
+    dest="trace_level",
+    type=str,
+    nargs=1,
+    help="Set 'elasticsearch.trace' logging level (e.g. 'INFO')",
+)
+parser.add_argument(
     "--duplicates",
     dest="dups",
     action="store_true",
@@ -648,7 +662,10 @@ if args.dry:
         dumpfile.write("[\n")
 else:
     # Fetch config and set up ES
-    es = Elastic()
+    es = Elastic(
+            logger_level=args.logger_level[0] if args.logger_level else None,
+            trace_level=args.trace_level[0] if args.trace_level else None
+        )
 
     # No point continuing if the index does not exist
     print("Checking that the database index %s exists ... " % es.db_mbox)
diff --git a/tools/plugins/elastic.py b/tools/plugins/elastic.py
index 63a20e6..95f488c 100755
--- a/tools/plugins/elastic.py
+++ b/tools/plugins/elastic.py
@@ -46,7 +46,7 @@ class Elastic:
     db_auditlog:        str
     dbname:             str
 
-    def __init__(self):
+    def __init__(self, logger_level=None, trace_level=None):
         # Fetch config
         config = ponymailconfig.PonymailConfig()
 
@@ -84,15 +84,18 @@ class Elastic:
         # Always allow this to be set; will be replaced as necessary by wait_for_active_shards
         self.consistency = config.get("elasticsearch", "write", fallback="quorum")
 
-        # elasticsearch logs lots of warnings on retries/connection failure
-        logging.getLogger("elasticsearch").setLevel(logging.ERROR)
+        if logger_level:
+            eslog = logging.getLogger("elasticsearch")
+            eslog.setLevel(logger_level)
+            eslog.addHandler(logging.StreamHandler())
+        else:
+            # elasticsearch logs lots of warnings on retries/connection failure
+            logging.getLogger("elasticsearch").setLevel(logging.ERROR)
 
-        #         # add debug
-        #         trace = logging.getLogger("elasticsearch.trace")
-        #         trace.setLevel(logging.DEBUG)
-        #         # create console handler
-        #         consoleHandler = logging.StreamHandler()
-        #         trace.addHandler(consoleHandler)
+        if trace_level:
+            trace = logging.getLogger("elasticsearch.trace")
+            trace.setLevel(trace_level)
+            trace.addHandler(logging.StreamHandler())
 
         self.es = Elasticsearch(
             [