Merge lp:~stub/launchpad/trivial into lp:launchpad

Proposed by Stuart Bishop
Status: Merged
Approved by: Stuart Bishop
Approved revision: 9965
Merged at revision: 12676
Proposed branch: lp:~stub/launchpad/trivial
Merge into: lp:launchpad
Prerequisite: lp:~jtv/launchpad/bug-741585
Diff against target: 67 lines (+22/-10)
2 files modified
lib/canonical/launchpad/utilities/looptuner.py (+2/-10)
lib/lp_sitecustomize.py (+20/-0)
To merge this branch: bzr merge lp:~stub/launchpad/trivial
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) code Approve
Review via email: mp+54692@code.launchpad.net

Commit message

[r=jtv][bug=741650] Override the root logger with an instance of LaunchpadLogger. Currently, code paths can fail when passed the root logger instead of a logger with our richer API.

Description of the change

Make our root logger be a LaunchpadLogger, so all logger instances have a consistent API we can rely on.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

I'll just have to trust you on the actual implications of this, but the code looks good.

review: Approve (code)
lp:~stub/launchpad/trivial updated
9966. By Stuart Bishop

Do more work replacing root logger, as bzrlib and zope have already created loggers on module import.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/utilities/looptuner.py'
2--- lib/canonical/launchpad/utilities/looptuner.py 2011-03-24 11:59:38 +0000
3+++ lib/canonical/launchpad/utilities/looptuner.py 2011-03-28 07:07:20 +0000
4@@ -25,7 +25,6 @@
5 MASTER_FLAVOR,
6 )
7 from canonical.lazr.utils import safe_hasattr
8-from lp.services.log.loglevels import DEBUG2
9
10
11 class LoopTuner:
12@@ -138,11 +137,7 @@
13 time_taken = new_clock - last_clock
14 last_clock = new_clock
15
16- # XXX JeroenVermeulen 2011-03-24 bug=741650: call debug2
17- # log method once we've ensured that the root logger has
18- # it.
19- self.log.log(
20- DEBUG2,
21+ self.log.debug2(
22 "Iteration %d (size %.1f): %.3f seconds",
23 iteration, chunk_size, time_taken)
24
25@@ -169,10 +164,7 @@
26 total_time = last_clock - self.start_time
27 average_size = total_size/max(1, iteration)
28 average_speed = total_size/max(1, total_time)
29- # XXX JeroenVermeulen 2011-03-24 bug=741650: call debug2 log
30- # method once we've ensured that the root logger has it.
31- self.log.log(
32- DEBUG2,
33+ self.log.debug2(
34 "Done. %d items in %d iterations, 3f seconds, "
35 "average size %f (%s/s)",
36 total_size, iteration, total_time, average_size,
37
38=== modified file 'lib/lp_sitecustomize.py'
39--- lib/lp_sitecustomize.py 2011-03-08 04:19:53 +0000
40+++ lib/lp_sitecustomize.py 2011-03-28 07:07:20 +0000
41@@ -49,6 +49,26 @@
42 # custom loglevels.
43 logging.setLoggerClass(loglevels.LaunchpadLogger)
44
45+ # Fix the root logger, replacing it with an instance of our
46+ # customized Logger. The original one is instantiated on import of
47+ # the logging module, so our override does not take effect without
48+ # this manual effort.
49+ old_root = logging.root
50+ new_root = loglevels.LaunchpadLogger('root', loglevels.WARNING)
51+
52+ # Fix globals.
53+ logging.root = new_root
54+ logging.Logger.root = new_root
55+
56+ # Fix manager.
57+ manager = logging.Logger.manager
58+ manager.root = new_root
59+
60+ # Fix existing Logger instances.
61+ for logger in manager.loggerDict.values():
62+ if getattr(logger, 'parent', None) is old_root:
63+ logger.parent = new_root
64+
65
66 def silence_bzr_logger():
67 """Install the NullHandler on the bzr logger to silence logs."""