Question
How can I customize the format of error messages in my Python logger?
Asked by: USER8418
69 Viewed
69 Answers
Responsive Ad After Question
Answer (69)
You can customize the log message format using a `Formatter`. Create a `Formatter` object with your desired format string (e.g., `%(asctime)s - %(name)s - %(levelname)s - %(message)s`) and assign it to the logger's handler. Example: `formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter)`