1

I've been banging my head on this one for a while. I have a Flask application that runs using Apache and mod_wsgi on RHEL 6 (so, Python 2.6, and Apache 2.2).

Anyway, I'm having this strange issue with the logging. I have the following logging class:

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)

Nothing to complicated there. In other modules, I instantiate the Logger class:

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

and go on logging stuff. Everything works fine... for a while...

So, my problem is this: After a random period of time, logging just stops. The app continues to run just fine, processing requests, etc. Just no logs until I restart Apache.

Previously, I was using a RotatingFileHandler, and had the same issue. At that point, I thought to myself, "I'll just switch to using the SyslogHandler." So, I did. Same problem.

I feel like I must be hitting some sort of resource limit or something, but I can not figure out where to start looking.

I'd appreciate any insight on where to start looking for answers. Thanks, Matt

  • This seems to be realted to using SMTPHandler, which might block. Some solutions are mentioned here: http://stackoverflow.com/questions/8616617/how-to-make-smtphandler-not-block – Jan Vlcinsky Jun 09 '14 at 21:28
  • Meantime I did a test with my [SO SMTP logging test](http://stackoverflow.com/a/24116085/346478) (which is not shown in that answer), and found, the difference is easily one or two seconds. With network lags one can easily enter some unexpected problem. I have used `Logbook`, but the solution for stdilb `logging` shall be conceptually the same. – Jan Vlcinsky Jun 11 '14 at 15:03

0 Answers0