Skip to content

Commit

Permalink
Checking the Logger for existing AirbrakeHandlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeyes committed Aug 23, 2014
1 parent 6938b55 commit 7eda24a
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions airbrake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

logging.basicConfig()

LOGGERS = {}


def getLogger(name=None, **kwargs):

Expand All @@ -34,19 +32,19 @@ def getLogger(name=None, **kwargs):
name = os.path.split(
callingpath.rpartition('.')[0] or callingpath)[-1]
name = "%s%s" % ('airbrake-python-', name)
logger = logging.getLogger(name)

if name in LOGGERS:
# check if it's already been configured
return LOGGERS[name]
if not has_airbrake_handler(logger):
ab = AirbrakeHandler(**kwargs)
logger.addHandler(ab)
if logger.getEffectiveLevel() == logging.NOTSET:
logger.setLevel(ab.level)
elif not logger.isEnabledFor(ab.level):
logger.setLevel(ab.level)

logger = logging.getLogger(name)
ab = AirbrakeHandler(**kwargs)
logger.addHandler(ab)
if logger.getEffectiveLevel() == logging.NOTSET:
logger.setLevel(ab.level)
elif not logger.isEnabledFor(ab.level):
logger.setLevel(ab.level)

# check if it's already been configured
LOGGERS[name] = logger
return logger


def has_airbrake_handler(logger):
return any([isinstance(handler, AirbrakeHandler)
for handler in logger.handlers])

0 comments on commit 7eda24a

Please sign in to comment.