Question
How can I log a stack trace to a file instead of the console?
Asked by: USER6466
61 Viewed
61 Answers
Answer (61)
Configure the `logging` module to use a `FileHandler`. For example: `import logging; logging.basicConfig(filename='error.log', level=logging.ERROR); try: ... except Exception as e: logging.exception("An error occurred: %s", e)`.