~ubuntu-branches/ubuntu/precise/duplicity/precise

« back to all changes in this revision

Viewing changes to debian/patches/08levelname.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Michael Terry
  • Date: 2011-06-13 11:53:19 UTC
  • Revision ID: james.westby@ubuntu.com-20110613115319-06dwp0st0yy59id0
Tags: 0.6.13-2ubuntu1
* debian/patches/07ubuntuone.dpatch:
  - Backported from trunk; adds Ubuntu One backend
* debian/patches/08levelname.dpatch:
  - Fixes logging issues introduced by above patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 08levelname.dpatch by  <mterry@ubuntu.com>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: Fix logging when other modules add log level names
 
6
 
 
7
@DPATCH@
 
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
 
11
@@ -3,6 +3,7 @@
 
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
 
16
 #
 
17
 # This file is part of duplicity.
 
18
 #
 
19
@@ -46,6 +47,14 @@
 
20
        more severe"""
 
21
     return DupToLoggerLevel(verb)
 
22
 
 
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"
 
30
+
 
31
 def Log(s, verb_level, code=1, extra=None, force_print=False):
 
32
     """Write s to stderr if verbosity level low enough"""
 
33
     global _logger
 
34
@@ -201,6 +210,7 @@
 
35
         global _logger
 
36
         logging.LogRecord.__init__(self, *args, **kwargs)
 
37
         self.controlLine = controlLine
 
38
+        self.levelName = LevelName(self.levelno)
 
39
 
 
40
 class DupLogger(logging.Logger):
 
41
     """Custom logger that creates special code-bearing records"""
 
42
@@ -229,18 +239,6 @@
 
43
     logging.setLoggerClass(DupLogger)
 
44
     _logger = logging.getLogger("duplicity")
 
45
 
 
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")
 
57
-
 
58
     # Default verbosity allows notices and above
 
59
     setverbosity(NOTICE)
 
60
 
 
61
@@ -258,7 +256,11 @@
 
62
        processes."""
 
63
     def __init__(self):
 
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")
 
71
 
 
72
     def format(self, record):
 
73
         s = logging.Formatter.format(self, record)
 
74
@@ -274,13 +276,8 @@
 
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')
 
87
 
 
88
 def add_fd(fd):
 
89
     """Add stream to which to write machine-readable logging"""