/usr/lib/python3/dist-packages/logging_tree/nodes.py is in python3-logging-tree 1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | """Routine that explores the `logging` hierarchy and builds a `Node` tree."""
import logging
def tree():
"""Return a tree of tuples representing the logger layout.
Each tuple looks like ``('logger-name', <Logger>, [...])`` where the
third element is a list of zero or more child tuples that share the
same layout.
"""
root = ('', logging.root, [])
nodes = {}
items = list(logging.root.manager.loggerDict.items()) # for Python 2 and 3
items.sort()
for name, logger in items:
nodes[name] = node = (name, logger, [])
i = name.rfind('.', 0, len(name) - 1) # same formula used in `logging`
if i == -1:
parent = root
else:
parent = nodes[name[:i]]
parent[2].append(node)
return root
|