Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 792412 - Multiple instances of LoggerListener are causing an infi…
Browse files Browse the repository at this point in the history
…nite loop due to duplicated handlers attached. r=jhammel
  • Loading branch information
whimboo committed Sep 21, 2012
1 parent e60624b commit f53ca04
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions mozmill/mozmill/logger.py
Expand Up @@ -12,6 +12,7 @@
import logging
import re
import sys
import uuid


class LoggerListener(object):
Expand All @@ -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 = {
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit f53ca04

Please sign in to comment.