Python日志处理程序死亡

时间:2014-06-09 18:51:39

标签: python apache logging flask mod-wsgi

我已经在这个问题上敲了一会儿。我有一个Flask应用程序在RHEL 6上使用Apache和mod_wsgi运行(因此,Python 2.6和Apache 2.2)。

无论如何,我在登录时遇到了这个奇怪的问题。我有以下日志记录类:

class Logger(object):

    def get_logger(self):
        return self.logger

    def __init__(self, loggername):
        self.logger = logging.getLogger(loggername)
        self.logger.setLevel(logging.DEBUG)
        syslog_handler = SysLogHandler(
            address='/dev/log',
            facility=SysLogHandler.LOG_LOCAL0
        )
        syslog_handler.setLevel(logging.DEBUG)
        syslog_handler.setFormatter(logging.Formatter('%(levelname)s - %(message)s'))
        email_handler = SMTPHandler(
            mailhost='smtp.example.com',
            fromaddr='error@example.com',
            toaddrs=['admins@example.com'],
            subject='Error Message')
        email_handler.setLevel(logging.ERROR)
        email_handler.setFormatter(logging.Formatter(
            '''
            Message type:   %(levelname)s
            Location:       %(pathname)s:%(lineno)d
            Module:         %(module)s
            Function:       %(funcName)s
            Time:           %(asctime)s

            Message:
            %(message)s
            '''))
        self.logger.addHandler(syslog_handler)
        self.logger.addHandler(email_handler)

那里没什么好复杂的。在其他模块中,我实例化了Logger类:

log = Logger('mymodule').get_logger()

继续记录东西。一切都很好......一段时间......

所以,我的问题是:经过一段随机的时间后,记录就停止了。应用程序继续运行得很好,处理请求等等。在重新启动Apache之前,没有日志。

以前,我使用的是RotatingFileHandler,并且遇到了同样的问题。那时,我心想,"我只是转而使用SyslogHandler。"所以我做了。同样的问题。

我觉得我必须达到某种资源限制或某种程度,但我无法弄清楚从哪里开始寻找。

我很欣赏任何有关从哪里开始寻找答案的见解。 谢谢, 马特

0 个答案:

没有答案