I want to check for errors in a particular background file, but the standard error stream is being controlled by the program in the foreground and the errors in the file in the question are not being displayed. I can use the logging
module and write output to a file, though. I was wondering how I can use this to log all exceptions, errors and their tracebacks.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
It's probably a bad idea to log any exception thrown within the program, since Python uses exceptions also for normal control flow.
Therefore you should only log uncaught exceptions. You can easily do this using a logger's
exception()
method, once you have an exception object.To handle all uncaught exceptions, you can either wrap your script's entry point in a
try...except
block, or by installing a custom exception handler by re-assigningsys.excepthook()
: