I've got a similar problem. I have a model file where I initialize the logger:
import logging, logging.handlers
def get_configured_logger(name):
logger = logging.getLogger(name)
if (len(logger.handlers) == 0):
# This logger has no handlers, so we can assume it hasn't yet been configured
# (Configure logger)
# Create RotatingFileHandler
import os
formatter = "%(asctime)s %(levelname)s %(process)s %(thread)s %(funcName)s():%(lineno)d %(message)s"
# rotate log file when it reaches 10MB
handler = logging.handlers.RotatingFileHandler(os.path.join(request.folder,'private/myapp.log'),maxBytes=10485760,backupCount=2)
handler.setFormatter(logging.Formatter(formatter))
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
if len(logger.handlers) > 1:
logger.debug('handler: ' + str(len(logger.handlers)))
return logger
# Assign application logger to a global var
logger = get_configured_logger(request.application)
sometimes it happens that an additional handler is added. After a few days sometimes there are 2 or even more handlers attached. Every log message is then printed multiple times in the log file.
The application is internal and has only few users. Therefor I'm using the integrated Rocket webserver (Linux). Has anyone an idea why this is happening?
Would rewriting the logger configuration with the logging.conf file help in this case? It's not that easy to simply rewrite and test it because the application is auto-deployed to different machines and it would be necessary to adapt the deployment process as well.
Alex