[PATCH 2/5] management: Enable configurable logging levels
Stephen Finucane
stephen at that.guru
Fri Nov 18 11:54:49 AEDT 2016
If we're hashing patches we don't want to out logging information. This
requires configurable log levels.
Signed-off-by: Stephen Finucane <stephen at that.guru>
Cc: Paul Jakma <paul at jakma.org>
---
patchwork/management/commands/__init__.py | 34 +++++++++++++++++++++++++++
patchwork/management/commands/parsearchive.py | 8 ++++++-
patchwork/management/commands/parsemail.py | 4 ++++
patchwork/settings/base.py | 2 +-
4 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/patchwork/management/commands/__init__.py b/patchwork/management/commands/__init__.py
index e69de29..fa9c174 100644
--- a/patchwork/management/commands/__init__.py
+++ b/patchwork/management/commands/__init__.py
@@ -0,0 +1,34 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Stephen Finucane <stephen at that.guru>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import logging
+
+
+def configure_logging(loggers, verbosity):
+ def set_loggers(loggers, level):
+ for logger in loggers:
+ logging.getLogger(logger).setLevel(level)
+
+ # rely on standard configuration for verbosity 1 (normal)
+ if verbosity == 0:
+ set_loggers(loggers, logging.ERROR)
+ elif verbosity == 1:
+ set_loggers(loggers, logging.INFO)
+ elif verbosity >= 2:
+ set_loggers(loggers, logging.DEBUG)
diff --git a/patchwork/management/commands/parsearchive.py b/patchwork/management/commands/parsearchive.py
index 40b2cc0..5f3a11a 100644
--- a/patchwork/management/commands/parsearchive.py
+++ b/patchwork/management/commands/parsearchive.py
@@ -26,6 +26,7 @@ import sys
import django
from django.core.management.base import BaseCommand
+from patchwork.management.commands import configure_logging
from patchwork import models
from patchwork.parser import parse_mail
@@ -63,6 +64,9 @@ class Command(BaseCommand):
dropped = 0
errors = 0
+ verbosity = int(options['verbosity'])
+ configure_logging(['patchwork.parser', __name__], verbosity)
+
# TODO(stephenfin): Support passing via stdin
path = args and args[0] or options['infile']
if not os.path.exists(path):
@@ -87,7 +91,9 @@ class Command(BaseCommand):
# somewhere for future reference?
errors += 1
- if (i % 10) == 0:
+ # we don't output this when using higher verbosities - logging
+ # provides enough information
+ if verbosity < 2 and (i % 10) == 0:
self.stdout.write('%06d/%06d\r' % (i, count), ending='')
self.stdout.flush()
diff --git a/patchwork/management/commands/parsemail.py b/patchwork/management/commands/parsemail.py
index 9adfb25..fd85763 100644
--- a/patchwork/management/commands/parsemail.py
+++ b/patchwork/management/commands/parsemail.py
@@ -27,6 +27,7 @@ from django.core.management import base
from django.utils import six
from patchwork.parser import parse_mail
+from patchwork.management.commands import configure_logging
logger = logging.getLogger(__name__)
@@ -58,6 +59,9 @@ class Command(base.BaseCommand):
def handle(self, *args, **options):
infile = args[0] if args else options['infile']
+ configure_logging(['patchwork.parser', __name__],
+ int(options['verbosity']))
+
if infile:
logger.info('Parsing mail loaded by filename')
if six.PY3:
diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py
index a32710f..d2b996b 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -185,7 +185,7 @@ LOGGING = {
},
'patchwork.parser': {
'handlers': ['console'],
- 'level': 'DEBUG',
+ 'level': 'INFO',
'propagate': False,
},
'patchwork.management.commands': {
--
2.7.4
More information about the Patchwork
mailing list