]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parsearchive: Fix logging
authorStephen Finucane <stephen@that.guru>
Wed, 19 Sep 2018 18:50:55 +0000 (19:50 +0100)
committerStephen Finucane <stephen@that.guru>
Thu, 20 Sep 2018 21:06:14 +0000 (22:06 +0100)
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.

In addition, the default logging level for the parser module is set to
'WARNING' to make it less chatty.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/management/commands/parsearchive.py
patchwork/parser.py
patchwork/settings/base.py

index 96f64fa7f11bbe8c09b5040487aed51252a31470..90bb6c030c6f98b2465911999dcde75632521121 100644 (file)
@@ -37,10 +37,24 @@ class Command(BaseCommand):
         dropped = 0
         errors = 0
 
+        verbosity = int(options['verbosity'])
+        if not verbosity:
+            level = logging.CRITICAL
+        elif verbosity == 1:
+            level = logging.ERROR
+        elif verbosity == 2:
+            level = logging.INFO
+        else:  # verbosity == 3
+            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)
+            logger.error('Invalid path: %s', path)
             sys.exit(1)
 
         # assume if <infile> is a directory, then we're passing a maildir
@@ -65,7 +79,7 @@ class Command(BaseCommand):
             for m in mbox:
                 pass
         except AttributeError:
-            logger.warning('Broken mbox/Maildir, aborting')
+            logger.error('Broken mbox/Maildir, aborting')
             return
 
         logger.info('Parsing %d mails', count)
@@ -81,10 +95,15 @@ class Command(BaseCommand):
                 # somewhere for future reference?
                 errors += 1
 
-            if (i % 10) == 0:
+            if verbosity < 3 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 +120,3 @@ class Command(BaseCommand):
                 'errors': errors,
                 'new': count - dropped - errors,
             })
-        mbox.close()
index 4ede8255679aa69a345b7c731d6998d036e4bb99..a61669f41532aba3d571c712264a7d1a9329fa7a 100644 (file)
@@ -950,7 +950,7 @@ def parse_mail(mail, list_id=None):
 
     hint = clean_header(mail.get('X-Patchwork-Hint', ''))
     if hint and hint.lower() == 'ignore':
-        logger.debug("Ignoring email due to 'ignore' hint")
+        logger.info("Ignoring email due to 'ignore' hint")
         return
 
     project = find_project(mail, list_id)
index 16ca712a8c5f85840177a4c1ad2c8923021abff0..3eb1f0e279fa5fe2dd3a3610c2a382904e5d7c42 100644 (file)
@@ -177,17 +177,17 @@ LOGGING = {
     'loggers': {
         'django': {
             'handlers': ['console'],
-            'level': 'INFO',
+            'level': 'WARNING',
             'propagate': True,
         },
         'patchwork.parser': {
             'handlers': ['console'],
-            'level': 'DEBUG',
+            'level': 'WARNING',
             'propagate': False,
         },
         'patchwork.management.commands': {
             'handlers': ['console', 'mail_admins'],
-            'level': 'INFO',
+            'level': 'WARNING',
             'propagate': True,
         },
     },