summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Keating <jkeating@redhat.com>2010-09-10 17:58:12 -0700
committerJesse Keating <jkeating@redhat.com>2010-09-10 17:58:12 -0700
commit76272ddc502454f95d2f2a54f038971476366bc1 (patch)
tree4e8ff034d91852eb5ef373948f155f6fcc1c85ca
parent93ffd2a67dc1b2a160e5ab44a9b140c1ef372c73 (diff)
downloadfedora-packager-76272ddc502454f95d2f2a54f038971476366bc1.tar.gz
fedora-packager-76272ddc502454f95d2f2a54f038971476366bc1.tar.xz
fedora-packager-76272ddc502454f95d2f2a54f038971476366bc1.zip
Fix up the logger for what goes where
Make sure that WARN, ERROR, and CRITICAL go to stderr, and that DEBUG and INFO go to stdout. This involves more configuration than it aught to, but that's python logging for ya.
-rwxr-xr-xsrc/fedpkg.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/fedpkg.py b/src/fedpkg.py
index 0eb96c6..ec54351 100755
--- a/src/fedpkg.py
+++ b/src/fedpkg.py
@@ -37,6 +37,13 @@ SECONDARY_ARCH_PKGS = {'sparc': ['silo', 'prtconf', 'lssbus', 'afbinit',
'ppc': ['ppc64-utils', 'yaboot'],
'arm': []}
+# Add a log filter class
+class StdoutFilter(logging.Filter):
+
+ def filter(self, record):
+ # If the record level is 20 (INFO) or lower, let it through
+ return record.levelno <= logging.INFO
+
# Add a class stolen from /usr/bin/koji to watch tasks
# this was cut/pasted from koji, and then modified for local use.
# The formatting is koji style, not the stile of this file. Do not use these
@@ -1066,7 +1073,11 @@ packages will be built sequentially.
# Parse the args
args = parser.parse_args()
- # setup the logger
+ # setup the logger -- This logger will take things of INFO or DEBUG and
+ # log it to stdout. Anything above that (WARN, ERROR, CRITICAL) will go
+ # to stderr. Normal operation will show anything INFO and above.
+ # Quiet hides INFO, while Verbose exposes DEBUG. In all cases WARN or
+ # higher are exposed (via stderr).
log = pyfedpkg.log
if args.v:
log.setLevel(logging.DEBUG)
@@ -1074,11 +1085,17 @@ packages will be built sequentially.
log.setLevel(logging.WARNING)
else:
log.setLevel(logging.INFO)
- # log things to stdout instead of stderr
- streamhandler = logging.StreamHandler(stream=sys.stdout)
formatter = logging.Formatter('%(message)s')
- streamhandler.setFormatter(formatter)
- log.addHandler(streamhandler)
+ # have to create a filter for the stdout stream to filter out WARN+
+ myfilt = StdoutFilter()
+ stdouthandler = logging.StreamHandler(stream=sys.stdout)
+ stdouthandler.addFilter(myfilt)
+ stdouthandler.setFormatter(formatter)
+ stderrhandler = logging.StreamHandler()
+ stderrhandler.setLevel(logging.WARNING)
+ stderrhandler.setFormatter(formatter)
+ log.addHandler(stdouthandler)
+ log.addHandler(stderrhandler)
# Run the necessary command
try: