Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception logging #149

Open
casesolved-co-uk opened this issue Sep 3, 2024 · 0 comments
Open

Exception logging #149

casesolved-co-uk opened this issue Sep 3, 2024 · 0 comments

Comments

@casesolved-co-uk
Copy link

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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant