Closed
Description
Documentation
https://docs.python.org/3/library/logging.html#logging.Handler.setFormatter
When providing a logger handler with a formatter class, there is no documentation stating if that formatter class needs to be initialized before passing it as an argument. Through trial and error, I found that it needs to be initialized first. Please either clarify the documentation or have underlying code check to see if the formatter is initialized yet.
Problemed formatter configuration:
handler.setFormatter(xml_log_formatter)
logging.info('test_msg')
Fixed formatter configuration:
handler.setFormatter(xml_log_formatter())
logging.info('test_msg')
Purposed code check (from a custom logging module):
#Instantiate formatter class (if needed)
if isinstance(cls.log_formatter, type):
cls.log_formatter = cls.log_formatter()
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Done
Status
Todo