power-mailinabox icon indicating copy to clipboard operation
power-mailinabox copied to clipboard

Exception logging

Open casesolved-co-uk opened this issue 5 months ago • 0 comments

I recently ran into #70 for exactly the same reason, and tried HARD to add an error log to capture exceptions. For the life of me couldn't figure out why it didn't work. I'm not familiar enough with Flask but followed all the docs and stackoverflow answers I could find.

It created the log file fine, but didn't output exceptions no matter what I tried.

Here's what I put in daemon.py, would be great if someone could make it work:

# fixes formatting character code output
import werkzeug
werkzeug.serving._log_add_style = False

def logfile_handler():
       import logging
       handler = logging.handlers.RotatingFileHandler(
               "/var/log/mailinabox.err.log",
               maxBytes=100000,
               backupCount=1,
       )
       handler.setLevel(logging.INFO)
       return handler


# I tried lots of things to make this work!!
@app.errorhandler(Exception)
def log_exception(e):
       app.logger.error("Exception")
       return e

....

              # after the create_syslog_handler() line
              app.logger.addHandler(logfile_handler())

casesolved-co-uk avatar Sep 03 '24 21:09 casesolved-co-uk