1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 08levelname.dpatch by <mterry@ubuntu.com>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: Fix logging when other modules add log level names
8
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' duplicity-0.6.13~/src/log.py duplicity-0.6.13/src/log.py
9
--- duplicity-0.6.13~/src/log.py 2011-04-02 13:48:22.000000000 -0400
10
+++ duplicity-0.6.13/src/log.py 2011-06-13 08:45:19.789684987 -0400
12
# Copyright 2002 Ben Escoto <ben@emerose.org>
13
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
14
# Copyright 2008 Michael Terry <mike@mterry.name>
15
+# Copyright 2011 Canonical Ltd
17
# This file is part of duplicity.
21
return DupToLoggerLevel(verb)
23
+def LevelName(level):
24
+ level = LoggerToDupLevel(level)
25
+ if level >= 9: return "DEBUG"
26
+ elif level >= 5: return "INFO"
27
+ elif level >= 3: return "NOTICE"
28
+ elif level >= 1: return "WARNING"
29
+ else: return "ERROR"
31
def Log(s, verb_level, code=1, extra=None, force_print=False):
32
"""Write s to stderr if verbosity level low enough"""
36
logging.LogRecord.__init__(self, *args, **kwargs)
37
self.controlLine = controlLine
38
+ self.levelName = LevelName(self.levelno)
40
class DupLogger(logging.Logger):
41
"""Custom logger that creates special code-bearing records"""
43
logging.setLoggerClass(DupLogger)
44
_logger = logging.getLogger("duplicity")
46
- # Set up our special level names
47
- logging.addLevelName(DupToLoggerLevel(0), "ERROR")
48
- logging.addLevelName(DupToLoggerLevel(1), "WARNING")
49
- logging.addLevelName(DupToLoggerLevel(2), "WARNING")
50
- logging.addLevelName(DupToLoggerLevel(3), "NOTICE")
51
- logging.addLevelName(DupToLoggerLevel(4), "NOTICE")
52
- logging.addLevelName(DupToLoggerLevel(5), "INFO")
53
- logging.addLevelName(DupToLoggerLevel(6), "INFO")
54
- logging.addLevelName(DupToLoggerLevel(7), "INFO")
55
- logging.addLevelName(DupToLoggerLevel(8), "INFO")
56
- logging.addLevelName(DupToLoggerLevel(9), "DEBUG")
58
# Default verbosity allows notices and above
64
# 'message' will be appended by format()
65
- logging.Formatter.__init__(self, "%(levelname)s %(controlLine)s")
66
+ # Note that we use our own, custom-created 'levelName' instead of the
67
+ # standard 'levelname'. This is because the standard 'levelname' can
68
+ # be adjusted by any library anywhere in our stack without us knowing.
69
+ # But we control 'levelName'.
70
+ logging.Formatter.__init__(self, "%(levelName)s %(controlLine)s")
72
def format(self, record):
73
s = logging.Formatter.format(self, record)
75
class MachineFilter(logging.Filter):
76
"""Filter that only allows levels that are consumable by other processes."""
77
def filter(self, record):
78
- # We only want to allow records that have level names. If the level
79
- # does not have an associated name, there will be a space as the
80
- # logging module expands levelname to "Level %d". This will confuse
81
- # consumers. Even if we dropped the space, random levels may not
82
- # mean anything to consumers.
83
- s = logging.getLevelName(record.levelno)
84
- return s.find(' ') == -1
85
+ # We only want to allow records that have our custom level names
86
+ return hasattr(record, 'levelName')
89
"""Add stream to which to write machine-readable logging"""