When (re)configuring logging, handle loggers which were in the previous configuration but are not in the new configuration. There's no point deleting them as other threads may continue to hold references to them; and by disabling them, you stop them doing any logging. However,
(existing, child_loggers, disable_existing)
| 176 | return handlers |
| 177 | |
| 178 | def _handle_existing_loggers(existing, child_loggers, disable_existing): |
| 179 | """ |
| 180 | When (re)configuring logging, handle loggers which were in the previous |
| 181 | configuration but are not in the new configuration. There's no point |
| 182 | deleting them as other threads may continue to hold references to them; |
| 183 | and by disabling them, you stop them doing any logging. |
| 184 | |
| 185 | However, don't disable children of named loggers, as that's probably not |
| 186 | what was intended by the user. Also, allow existing loggers to NOT be |
| 187 | disabled if disable_existing is false. |
| 188 | """ |
| 189 | root = logging.root |
| 190 | for log in existing: |
| 191 | logger = root.manager.loggerDict[log] |
| 192 | if log in child_loggers: |
| 193 | if not isinstance(logger, logging.PlaceHolder): |
| 194 | logger.setLevel(logging.NOTSET) |
| 195 | logger.handlers = [] |
| 196 | logger.propagate = True |
| 197 | else: |
| 198 | logger.disabled = disable_existing |
| 199 | |
| 200 | def _install_loggers(cp, handlers, disable_existing): |
| 201 | """Create and install loggers""" |
no test coverage detected
searching dependent graphs…