diff --git a/swift/common/middleware/swauth.py b/swift/common/middleware/swauth.py index 3399fd06a4..5965e710ac 100644 --- a/swift/common/middleware/swauth.py +++ b/swift/common/middleware/swauth.py @@ -1321,6 +1321,8 @@ class Swauth(object): return False def posthooklogger(self, env, req): + if not req.path.startswith(self.auth_prefix): + return response = getattr(req, 'response', None) if not response: return diff --git a/swift/common/utils.py b/swift/common/utils.py index 479c4ecc30..8da3d1f8f4 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -409,28 +409,35 @@ def get_logger(conf, name=None, log_to_console=False, log_route=None): logger = logging.getLogger() else: logger = logging.getLogger(log_route) - if not hasattr(get_logger, 'handlers'): - get_logger.handlers = {} + logger.propagate = False + if not hasattr(get_logger, 'handler4facility'): + get_logger.handler4facility = {} facility = getattr(SysLogHandler, conf.get('log_facility', 'LOG_LOCAL0'), SysLogHandler.LOG_LOCAL0) - if facility in get_logger.handlers: - logger.removeHandler(get_logger.handlers[facility]) - get_logger.handlers[facility].close() - del get_logger.handlers[facility] + if facility in get_logger.handler4facility: + logger.removeHandler(get_logger.handler4facility[facility]) + get_logger.handler4facility[facility].close() + del get_logger.handler4facility[facility] if log_to_console: # check if a previous call to get_logger already added a console logger if hasattr(get_logger, 'console') and get_logger.console: logger.removeHandler(get_logger.console) get_logger.console = logging.StreamHandler(sys.__stderr__) logger.addHandler(get_logger.console) - get_logger.handlers[facility] = \ + get_logger.handler4facility[facility] = \ SysLogHandler(address='/dev/log', facility=facility) - logger.addHandler(get_logger.handlers[facility]) + if not hasattr(get_logger, 'handler4logger'): + get_logger.handler4logger = {} + if logger in get_logger.handler4logger: + logger.removeHandler(get_logger.handler4logger[logger]) + get_logger.handler4logger[logger] = \ + get_logger.handler4facility[facility] + logger.addHandler(get_logger.handler4facility[facility]) logger.setLevel( getattr(logging, conf.get('log_level', 'INFO').upper(), logging.INFO)) adapted_logger = LogAdapter(logger) formatter = NamedFormatter(name, adapted_logger) - get_logger.handlers[facility].setFormatter(formatter) + get_logger.handler4facility[facility].setFormatter(formatter) if hasattr(get_logger, 'console'): get_logger.console.setFormatter(formatter) return adapted_logger diff --git a/test/unit/common/test_daemon.py b/test/unit/common/test_daemon.py index 015928f670..a4addcee51 100644 --- a/test/unit/common/test_daemon.py +++ b/test/unit/common/test_daemon.py @@ -28,7 +28,7 @@ class MyDaemon(daemon.Daemon): def __init__(self, conf): self.conf = conf - self.logger = utils.get_logger(None) + self.logger = utils.get_logger(None, 'server') MyDaemon.forever_called = False MyDaemon.once_called = False @@ -97,7 +97,7 @@ user = %s # test user quit MyDaemon.run_forever = MyDaemon.run_quit sio = StringIO() - logger = logging.getLogger() + logger = logging.getLogger('server') logger.addHandler(logging.StreamHandler(sio)) logger = utils.get_logger(None, 'server') daemon.run_daemon(MyDaemon, conf_file, logger=logger) diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 94257415f1..0c81b15698 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -287,7 +287,7 @@ Error: unable to locate %s def test_get_logger(self): sio = StringIO() - logger = logging.getLogger() + logger = logging.getLogger('server') logger.addHandler(logging.StreamHandler(sio)) logger = utils.get_logger(None, 'server') logger.warn('test1')