Permalink
Browse files

Bug 792412 - Multiple instances of LoggerListener are causing an infi…

…nite loop due to duplicated handlers attached. r=jhammel
  • Loading branch information...
1 parent e60624b commit f53ca04e3ccf665045fc70ac7d690331469ce8ea @whimboo whimboo committed Sep 21, 2012
Showing with 7 additions and 9 deletions.
  1. +7 −9 mozmill/mozmill/logger.py
View
16 mozmill/mozmill/logger.py
@@ -12,6 +12,7 @@
import logging
import re
import sys
+import uuid
class LoggerListener(object):
@@ -20,7 +21,10 @@ class LoggerListener(object):
### methods for the EventHandler interface
def __init__(self, log_file=None, console_level="INFO", file_level="INFO",
- format="pprint-color", debug=False):
+ format="pprint-color", debug=False, console_stream=sys.stdout):
+ self.format = format
+ self.debug = debug
+
template = "%(levelname)s | %(message)s"
levels = {
@@ -44,12 +48,12 @@ def __init__(self, log_file=None, console_level="INFO", file_level="INFO",
for name in self.custom_levels:
logging.addLevelName(self.custom_levels[name], name)
- self.logger = logging.getLogger('mozmill')
+ self.logger = logging.getLogger('mozmill.%s' % uuid.uuid1())
self.logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(template)
if console_level:
- console = logging.StreamHandler()
+ console = logging.StreamHandler(console_stream)
if format == "pprint-color":
formatter = ColorFormatter(template)
console.setFormatter(formatter)
@@ -62,12 +66,6 @@ def __init__(self, log_file=None, console_level="INFO", file_level="INFO",
handler.setLevel(levels[file_level])
self.logger.addHandler(handler)
- sys.stdout = self.StdOutLogger(self.logger)
- sys.stderr = self.StdErrLogger(self.logger)
-
- self.format = format
- self.debug = debug
-
class StdOutLogger(object):
def __init__(self, logger):
self.logger = logger

0 comments on commit f53ca04

Please sign in to comment.