Create and install loggers
(cp, handlers, disable_existing)
| 198 | logger.disabled = disable_existing |
| 199 | |
| 200 | def _install_loggers(cp, handlers, disable_existing): |
| 201 | """Create and install loggers""" |
| 202 | |
| 203 | # configure the root first |
| 204 | llist = cp["loggers"]["keys"] |
| 205 | llist = llist.split(",") |
| 206 | llist = list(_strip_spaces(llist)) |
| 207 | llist.remove("root") |
| 208 | section = cp["logger_root"] |
| 209 | root = logging.root |
| 210 | log = root |
| 211 | if "level" in section: |
| 212 | level = section["level"] |
| 213 | log.setLevel(level) |
| 214 | for h in root.handlers[:]: |
| 215 | root.removeHandler(h) |
| 216 | hlist = section["handlers"] |
| 217 | if len(hlist): |
| 218 | hlist = hlist.split(",") |
| 219 | hlist = _strip_spaces(hlist) |
| 220 | for hand in hlist: |
| 221 | log.addHandler(handlers[hand]) |
| 222 | |
| 223 | #and now the others... |
| 224 | #we don't want to lose the existing loggers, |
| 225 | #since other threads may have pointers to them. |
| 226 | #existing is set to contain all existing loggers, |
| 227 | #and as we go through the new configuration we |
| 228 | #remove any which are configured. At the end, |
| 229 | #what's left in existing is the set of loggers |
| 230 | #which were in the previous configuration but |
| 231 | #which are not in the new configuration. |
| 232 | existing = list(root.manager.loggerDict.keys()) |
| 233 | #The list needs to be sorted so that we can |
| 234 | #avoid disabling child loggers of explicitly |
| 235 | #named loggers. With a sorted list it is easier |
| 236 | #to find the child loggers. |
| 237 | existing.sort() |
| 238 | #We'll keep the list of existing loggers |
| 239 | #which are children of named loggers here... |
| 240 | child_loggers = [] |
| 241 | #now set up the new ones... |
| 242 | for log in llist: |
| 243 | section = cp["logger_%s" % log] |
| 244 | qn = section["qualname"] |
| 245 | propagate = section.getint("propagate", fallback=1) |
| 246 | logger = logging.getLogger(qn) |
| 247 | if qn in existing: |
| 248 | i = existing.index(qn) + 1 # start with the entry after qn |
| 249 | prefixed = qn + "." |
| 250 | pflen = len(prefixed) |
| 251 | num_existing = len(existing) |
| 252 | while i < num_existing: |
| 253 | if existing[i][:pflen] == prefixed: |
| 254 | child_loggers.append(existing[i]) |
| 255 | i += 1 |
| 256 | existing.remove(qn) |
| 257 | if "level" in section: |
no test coverage detected
searching dependent graphs…