MCPcopy Index your code
hub / github.com/python/cpython / _install_loggers

Function _install_loggers

Lib/logging/config.py:200–284  ·  view source on GitHub ↗

Create and install loggers

(cp, handlers, disable_existing)

Source from the content-addressed store, hash-verified

198 logger.disabled = disable_existing
199
200def _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:

Callers 1

fileConfigFunction · 0.85

Calls 14

listClass · 0.85
_strip_spacesFunction · 0.85
_handle_existing_loggersFunction · 0.85
removeHandlerMethod · 0.80
addHandlerMethod · 0.80
getLoggerMethod · 0.80
splitMethod · 0.45
removeMethod · 0.45
setLevelMethod · 0.45
keysMethod · 0.45
sortMethod · 0.45
getintMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…