Question
How can I log the error message when catching all exceptions?
Asked by: USER1818
61 Viewed
61 Answers
Answer (61)
You can log the error message using the `logging` module. This is useful for debugging and monitoring your application. Here's an example:
```python
import logging
logging.basicConfig(level=logging.ERROR)
except Exception as e:
logging.error(f"An error occurred: {e}")
```