Install and return handlers
(cp, formatters)
| 138 | |
| 139 | |
| 140 | def _install_handlers(cp, formatters): |
| 141 | """Install and return handlers""" |
| 142 | hlist = cp["handlers"]["keys"] |
| 143 | if not len(hlist): |
| 144 | return {} |
| 145 | hlist = hlist.split(",") |
| 146 | hlist = _strip_spaces(hlist) |
| 147 | handlers = {} |
| 148 | fixups = [] #for inter-handler references |
| 149 | for hand in hlist: |
| 150 | section = cp["handler_%s" % hand] |
| 151 | klass = section["class"] |
| 152 | fmt = section.get("formatter", "") |
| 153 | try: |
| 154 | klass = eval(klass, vars(logging)) |
| 155 | except (AttributeError, NameError): |
| 156 | klass = _resolve(klass) |
| 157 | args = section.get("args", '()') |
| 158 | args = eval(args, vars(logging)) |
| 159 | kwargs = section.get("kwargs", '{}') |
| 160 | kwargs = eval(kwargs, vars(logging)) |
| 161 | h = klass(*args, **kwargs) |
| 162 | h.name = hand |
| 163 | if "level" in section: |
| 164 | level = section["level"] |
| 165 | h.setLevel(level) |
| 166 | if len(fmt): |
| 167 | h.setFormatter(formatters[fmt]) |
| 168 | if issubclass(klass, logging.handlers.MemoryHandler): |
| 169 | target = section.get("target", "") |
| 170 | if len(target): #the target handler may not be loaded yet, so keep for later... |
| 171 | fixups.append((h, target)) |
| 172 | handlers[hand] = h |
| 173 | #now all handlers are loaded, fixup inter-handler references... |
| 174 | for h, t in fixups: |
| 175 | h.setTarget(handlers[t]) |
| 176 | return handlers |
| 177 | |
| 178 | def _handle_existing_loggers(existing, child_loggers, disable_existing): |
| 179 | """ |
no test coverage detected
searching dependent graphs…