def configure_logging(add_handler, log=log):
_ignore_log_keys = set(logging.makeLogRecord({}).__dict__)<EOL>def _json_format(record):<EOL><INDENT>extras = '<STR_LIT:U+0020>'.join(<EOL>"<STR_LIT>" % (k, record.__dict__[k])<EOL>for k in set(record.__dict__).difference(_ignore_log_keys))<EOL>if extras:<EOL><INDENT>record.msg = "<STR_LIT>" % (record.msg, extras)<EOL><DEDENT>return record<EOL><DEDENT>class ColoredJsonFormatter(ColoredFormatter):<EOL><INDENT>def format(self, record):<EOL><INDENT>record = _json_format(record)<EOL>return super(ColoredJsonFormatter, self).format(record)<EOL><DEDENT><DEDENT>if isinstance(add_handler, logging.Handler):<EOL><INDENT>log.addHandler(add_handler)<EOL><DEDENT>elif add_handler is True:<EOL><INDENT>if not any(isinstance(h, logging.StreamHandler) for h in log.handlers):<EOL><INDENT>_h = logging.StreamHandler()<EOL>_h.setFormatter(ColoredJsonFormatter(<EOL>"<STR_LIT>",<EOL>reset=True<EOL>))<EOL>log.addHandler(_h)<EOL><DEDENT><DEDENT>elif not log.handlers:<EOL><INDENT>log.addHandler(logging.NullHandler())<EOL><DEDENT>log.setLevel(logging.DEBUG)<EOL>log.propagate = False<EOL>return log<EOL>
Configure log records.  If adding a handler, make the formatter print all
passed in key:value data.
    ie log.extra('msg', extra=dict(a=1))
    generates  'msg  a=1'

`add_handler` (True, False, None, or Handler instance)
    if True, add a logging.StreamHandler() instance
    if False, do not add any handlers.
    if given a handler instance, add that the the logger