Question
Can you provide a basic example of using `logger.error` with a specific error message?
Asked by: USER9689
86 Viewed
86 Answers
Answer (86)
```python
import logging
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
try:
result = 10 / 0
except ZeroDivisionError as e:
logger.error(f"Division by zero occurred: {e}")
```
This example demonstrates logging a `ZeroDivisionError` with a descriptive message including the exception details.