[Reproducible-commits] [misc] 04/06: extract logger setup
Chris West
faux-guest at moszumanska.debian.org
Mon Dec 14 12:06:58 UTC 2015
This is an automated email from the git hooks/post-receive script.
faux-guest pushed a commit to branch master
in repository misc.
commit e1b3f737ba4593cbd99bc981521d75f83e1cfd85
Author: Chris West (Faux) <git at goeswhere.com>
Date: Mon Dec 14 11:24:18 2015 +0000
extract logger setup
---
clean-notes | 9 ++-------
logger.py | 13 +++++++++++++
yamlfiles.py | 3 +++
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/clean-notes b/clean-notes
index 623307a..07db71c 100755
--- a/clean-notes
+++ b/clean-notes
@@ -8,7 +8,6 @@
#
# Depends: python3 python3-apt python3-yaml python3-requests python3-psycopg2
-import logging
from apt_pkg import version_compare
import apt
@@ -17,6 +16,7 @@ import psycopg2
import yaml
import yamlfiles
+import logger
from remote import load_reproducible_status, RB_SITE
# "apt" is to avoid adding an ugly "apt_pkg.init()" call to fix a "ValueError:
@@ -76,12 +76,7 @@ if __name__ == '__main__':
if feature in args.disable:
args.disable.remove(feature)
-log = logging.getLogger(__name__)
-log.setLevel(logging.DEBUG if args.verbose else logging.INFO)
-sh = logging.StreamHandler()
-sh.setFormatter(logging.Formatter('{levelname[0]}: {message}', style='{'))
-log.addHandler(sh)
-
+log = logger.setup_logging(__name__, args.verbose)
log.debug(args)
# pyyaml does not check for duplicates when reading yaml.
diff --git a/logger.py b/logger.py
new file mode 100644
index 0000000..d0849dd
--- /dev/null
+++ b/logger.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+import logging
+
+
+def setup_logging(name, verbose=False):
+ log = logging.getLogger(name)
+ log.setLevel(logging.DEBUG if verbose else logging.INFO)
+ sh = logging.StreamHandler()
+ sh.setFormatter(logging.Formatter('{levelname[0]}: {message}', style='{'))
+ log.addHandler(sh)
+
+ return log
diff --git a/yamlfiles.py b/yamlfiles.py
index 042dddb..be45f1a 100644
--- a/yamlfiles.py
+++ b/yamlfiles.py
@@ -4,15 +4,18 @@
import sys
import yaml
+import logger
NOTES_YAML = 'packages.yml'
+log = logger.setup_logging(__name__)
def load_notes():
try:
with open(NOTES_YAML, encoding='utf-8') as f:
return yaml.safe_load(f)
except FileNotFoundError:
+
log.error('%s has not been found in your current directory. Please '
'cd to the notes directory', NOTES_YAML)
sys.exit(1)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/misc.git
More information about the Reproducible-commits
mailing list