@@ -172,8 +172,28 @@ def _install_handlers(cp, formatters):
172172 h .setTarget (handlers [t ])
173173 return handlers
174174
175+ def _handle_existing_loggers (existing , child_loggers , disable_existing ):
176+ """
177+ When (re)configuring logging, handle loggers which were in the previous
178+ configuration but are not in the new configuration. There's no point
179+ deleting them as other threads may continue to hold references to them;
180+ and by disabling them, you stop them doing any logging.
181+
182+ However, don't disable children of named loggers, as that's probably not
183+ what was intended by the user. Also, allow existing loggers to NOT be
184+ disabled if disable_existing is false.
185+ """
186+ root = logging .root
187+ for log in existing :
188+ logger = root .manager .loggerDict [log ]
189+ if log in child_loggers :
190+ logger .level = logging .NOTSET
191+ logger .handlers = []
192+ logger .propagate = True
193+ elif disable_existing :
194+ logger .disabled = True
175195
176- def _install_loggers (cp , handlers , disable_existing_loggers ):
196+ def _install_loggers (cp , handlers , disable_existing ):
177197 """Create and install loggers"""
178198
179199 # configure the root first
@@ -254,15 +274,15 @@ def _install_loggers(cp, handlers, disable_existing_loggers):
254274 #and by disabling them, you stop them doing any logging.
255275 #However, don't disable children of named loggers, as that's
256276 #probably not what was intended by the user.
257- for log in existing :
258- logger = root .manager .loggerDict [log ]
259- if log in child_loggers :
260- logger .level = logging .NOTSET
261- logger .handlers = []
262- logger .propagate = 1
263- elif disable_existing_loggers :
264- logger .disabled = 1
265-
277+ # for log in existing:
278+ # logger = root.manager.loggerDict[log]
279+ # if log in child_loggers:
280+ # logger.level = logging.NOTSET
281+ # logger.handlers = []
282+ # logger.propagate = 1
283+ # elif disable_existing_loggers:
284+ # logger.disabled = 1
285+ _handle_existing_loggers ( existing , child_loggers , disable_existing )
266286
267287IDENTIFIER = re .compile ('^[a-z_][a-z0-9_]*$' , re .I )
268288
@@ -617,14 +637,16 @@ def configure(self):
617637 #and by disabling them, you stop them doing any logging.
618638 #However, don't disable children of named loggers, as that's
619639 #probably not what was intended by the user.
620- for log in existing :
621- logger = root .manager .loggerDict [log ]
622- if log in child_loggers :
623- logger .level = logging .NOTSET
624- logger .handlers = []
625- logger .propagate = True
626- elif disable_existing :
627- logger .disabled = True
640+ #for log in existing:
641+ # logger = root.manager.loggerDict[log]
642+ # if log in child_loggers:
643+ # logger.level = logging.NOTSET
644+ # logger.handlers = []
645+ # logger.propagate = True
646+ # elif disable_existing:
647+ # logger.disabled = True
648+ _handle_existing_loggers (existing , child_loggers ,
649+ disable_existing )
628650
629651 # And finally, do the root logger
630652 root = config .get ('root' , None )
0 commit comments