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