[PATCH 1/2] parsearchive: Fix logging

Stephen Finucane stephen at that.guru
Thu Sep 20 06:25:14 AEST 2018


We should use a counter normally, avoid using the counter and emit logs
when more detailed output is requested, and emit nothing when no output
is requested.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/management/commands/parsearchive.py | 22 ++++++++++++++++---
 patchwork/settings/base.py                    |  2 +-
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/patchwork/management/commands/parsearchive.py b/patchwork/management/commands/parsearchive.py
index 96f64fa7..3ef91f51 100644
--- a/patchwork/management/commands/parsearchive.py
+++ b/patchwork/management/commands/parsearchive.py
@@ -37,10 +37,22 @@ class Command(BaseCommand):
         dropped = 0
         errors = 0
 
+        verbosity = int(options['verbosity'])
+        level = None
+        if not verbosity:
+            level = logging.ERROR
+        elif verbosity > 1:  # use defaults for verbosity == 1
+            level = logging.DEBUG
+
+        if level:
+            logger.setLevel(level)
+            logging.getLogger('patchwork.parser').setLevel(level)
+
         # TODO(stephenfin): Support passing via stdin
         path = args and args[0] or options['infile']
         if not os.path.exists(path):
-            self.stdout.write('Invalid path: %s' % path)
+            if verbosity:
+                self.stdout.write('Invalid path: %s' % path)
             sys.exit(1)
 
         # assume if <infile> is a directory, then we're passing a maildir
@@ -81,10 +93,15 @@ class Command(BaseCommand):
                 # somewhere for future reference?
                 errors += 1
 
-            if (i % 10) == 0:
+            if verbosity == 1 and (i % 10) == 0:
                 self.stdout.write('%06d/%06d\r' % (i, count), ending='')
                 self.stdout.flush()
 
+        mbox.close()
+
+        if not verbosity:
+            return
+
         self.stdout.write(
             'Processed %(total)d messages -->\n'
             '  %(covers)4d cover letters\n'
@@ -101,4 +118,3 @@ class Command(BaseCommand):
                 'errors': errors,
                 'new': count - dropped - errors,
             })
-        mbox.close()
diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py
index 16ca712a..34f6a4a6 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -182,7 +182,7 @@ LOGGING = {
         },
         'patchwork.parser': {
             'handlers': ['console'],
-            'level': 'DEBUG',
+            'level': 'INFO',
             'propagate': False,
         },
         'patchwork.management.commands': {
-- 
2.17.1



More information about the Patchwork mailing list