You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for handler in list(logger_instance.handlers):
logger_instance.removeHandler(handler)
Note: none of the options from the linked SO question is thread safe, but Python so far does not provide method to safely cleanup all handlers in one instruction.
The text was updated successfully, but these errors were encountered:
kuchara
changed the title
[Bug] Removing handlers in Backround Logger extension removes only one handler.
[Bug] Removing handlers in Background Logger extension removes only one handler.
Jul 22, 2024
Describe the bug
setup_server_logging()
@extensions/logging/logger.py
(https://github.com/sanic-org/sanic-ext/blob/main/sanic_ext/extensions/logging/logger.py#L49) mutateslogger_instance.handlers
list while iterating over it. This is not correct.If there are 2 handlers, most often, only one of them is being removed.
To Reproduce
N/A
Expected behavior
Mentioned code should remove all handlers, and replace them by a QueueHandler instance.
Environment (please complete the following information):
Additional context
My proposal to fix would be something like described in https://stackoverflow.com/questions/7484454/removing-handlers-from-pythons-logging-loggers :
Note: none of the options from the linked SO question is thread safe, but Python so far does not provide method to safely cleanup all handlers in one instruction.
See also on mutating list while iterating: https://discuss.python.org/t/how-safe-documented-is-it-to-mutate-a-list-being-iterated/18929
The text was updated successfully, but these errors were encountered: