From 755bb6ea3f47accb72f99c3c722514b8e70f176e Mon Sep 17 00:00:00 2001
From: Alan De Smet <alan.desmet@ssec.wisc.edu>
Date: Fri, 3 Sep 2021 16:55:48 +0000
Subject: [PATCH] Remove logging.summary

It was an overly clever hack. Manage summaries directly
---
 example/aitf-data-for-run     | 14 +++++++++++---
 example/aitf-update-cache     | 14 +++++++++++---
 example/aitf/argparsetools.py | 22 +++++++++++-----------
 example/aitf/conlog.py        | 14 --------------
 4 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/example/aitf-data-for-run b/example/aitf-data-for-run
index 7b3e66b..cfa29c3 100755
--- a/example/aitf-data-for-run
+++ b/example/aitf-data-for-run
@@ -80,10 +80,13 @@ def hack_oisst_preliminary_filename(filename):
     return re.sub(r'(avhrr-only-v2.\d{8})_preliminary(.nc)', r'\1\2', filename)
 
 
-def log_download_report(name, stats):
-    logging.summary(name)
+def yes_download_report(name, stats):
+    sys.stderr.write(name+"\n")
     for x in stats.report():
-        logging.summary("    "+x)
+        sys.stderr.write("    "+x+"\n")
+
+def no_download_report(name, stats):
+    pass
 
 
 
@@ -91,6 +94,11 @@ def main():
     aitf.conlog.setup_logging()
     args = parse_args()
 
+    if args.want_summary:
+        log_download_report = yes_download_report
+    else:
+        log_download_report = no_download_report
+
     do_download = not args.cache_only
 
     cache_dir = args.cache
diff --git a/example/aitf-update-cache b/example/aitf-update-cache
index 04be032..b394c07 100755
--- a/example/aitf-update-cache
+++ b/example/aitf-update-cache
@@ -92,10 +92,13 @@ def parse_args():
 
 
 
-def log_download_report(name, stats):
-    logging.summary(name)
+def yes_download_report(name, stats):
+    sys.stderr.write(name+"\n")
     for x in stats.report():
-        logging.summary("    "+x)
+        sys.stderr.write("    "+x+"\n")
+
+def no_download_report(name, stats):
+    pass
 
 class CleaningStats:
     def __init__(self):
@@ -189,6 +192,11 @@ def main():
     else:
         progress = None
 
+    if args.want_summary:
+        log_download_report = yes_download_report
+    else:
+        log_download_report = no_download_report
+
     sststats = aitf.ancil.SST.update_cache(args.dir,
             start_time=args.oldest,
             end_time=args.newest,
diff --git a/example/aitf/argparsetools.py b/example/aitf/argparsetools.py
index c7ad4b5..880e866 100644
--- a/example/aitf/argparsetools.py
+++ b/example/aitf/argparsetools.py
@@ -36,13 +36,15 @@ def initialize_logging_level_info():
     import logging
     global logging_levels
     # Need to delay until logging is configured
-    logging_levels = [ ('warnings', logging.WARNING) ]
-    # These are from conlog, but I don't want to depend on them.
-    if hasattr(logging,'SUMMARY'): logging_levels += [ ('a summary', logging.SUMMARY) ]
-    # Not a "real" logging level
-    logging_levels += [ ('progress', logging_levels[-1][1]) ]
-    logging_levels += [('general information', logging.INFO),
-            ('debugging information', logging.DEBUG) ]
+    logging_levels = [
+            ('warnings', logging.WARNING),
+            # These next two are not "real" logging levels
+            # but they control output
+            ('a summary', logging.WARNING),
+            ('progress', logging.WARNING),
+            ('general information', logging.INFO),
+            ('debugging information', logging.DEBUG),
+            ]
 
 def add_verbose_quiet_args(parser):
     import logging
@@ -73,10 +75,8 @@ def process_verbosity(args):
     args.log_level = logging_levels[args.verbosity][1]
     if args.silent:
         args.log_level = logging.ERROR
-    if args.verbosity >= 2:
-        args.want_progress = True
-    else:
-        args.want_progress = False
+    args.want_progress = args.verbosity >= 2
+    args.want_summary = args.verbosity >= 1
     logging.getLogger().setLevel(args.log_level)
 
 
diff --git a/example/aitf/conlog.py b/example/aitf/conlog.py
index 24457b2..b3a6da0 100644
--- a/example/aitf/conlog.py
+++ b/example/aitf/conlog.py
@@ -20,19 +20,6 @@
 import logging
 import sys
 
-def create_log_level(level, name):
-    logging.addLevelName(level, name.upper())
-    def logger_func(self, message, *args, **kws):
-        if self.isEnabledFor(level):
-            self._log(level, message, args, **kws)
-    def logging_func(message, *args, **kws):
-        logging.log(level, message, *args, **kws)
-    setattr(logging.Logger, name.lower(), logger_func)
-    setattr(logging, name.lower(), logging_func)
-    setattr(logging, name.upper(), level)
-    logging.basicConfig()
-
-
 def add_console_logging():
     """ Log to console, prefixing entries with the log level
 
@@ -68,6 +55,5 @@ def add_console_logging():
     return console_handler
 
 def setup_logging():
-    create_log_level(25, "SUMMARY")
     logging.basicConfig()
     add_console_logging()
-- 
GitLab