Can you provide a basic example of using `logger.error` with a specific error message?

Question

Grade: Education Subject: Support
Can you provide a basic example of using `logger.error` with a specific error message?
Asked by:
86 Viewed 86 Answers

Answer (86)

Best Answer
(328)
```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.