def _make_json(_event): event = dict(_event) level = event.pop("log_level", LogLevel.info).name # as soon as possible, we wish to give up if this event is # outside our target log-level; this is to prevent # (de-)serializing all the debug() messages (for example) from # workers to the controller. if log_levels.index(level) > log_levels.index(get_global_log_level()): return done_json = { "level": level, "namespace": event.pop("log_namespace", '') } eventText = formatEvent(event) if "log_failure" in event: # This is a traceback. Print it. traceback = event["log_failure"].getTraceback() if not six.PY3: traceback = traceback.decode('utf-8') linesep = os.linesep.decode('utf-8') else: linesep = os.linesep eventText = eventText + linesep + traceback done_json["text"] = escape_formatting(eventText) try: event.pop("log_logger", "") event.pop("log_format", "") event.pop("log_source", "") event.pop("log_system", "") event.pop("log_failure", "") event.pop("failure", "") event.update(done_json) text = encoder.encode(event) except Exception: text = encoder.encode({ "text": done_json["text"], "level": "error", "namespace": "crossbar._logging" }) if not isinstance(text, six.text_type): text = text.decode('utf8') print(text, end=record_separator, file=outFile) outFile.flush()
def _make_json(_event): event = dict(_event) level = event.pop("log_level", LogLevel.info).name # as soon as possible, we wish to give up if this event is # outside our target log-level; this is to prevent # (de-)serializing all the debug() messages (for example) from # workers to the controller. if log_levels.index(level) > log_levels.index(get_global_log_level()): return done_json = { "level": level, "namespace": event.pop("log_namespace", '') } eventText = formatEvent(event) if "log_failure" in event: # This is a traceback. Print it. traceback = event["log_failure"].getTraceback() if not six.PY3: traceback = traceback.decode('utf-8') linesep = os.linesep.decode('utf-8') else: linesep = os.linesep eventText = eventText + linesep + traceback done_json["text"] = escape_formatting(eventText) try: event.pop("log_logger", "") event.pop("log_format", "") event.pop("log_source", "") event.pop("log_system", "") event.pop("log_failure", "") event.pop("failure", "") event.update(done_json) text = encoder.encode(event) except Exception: text = encoder.encode({ "text": done_json["text"], "level": "error", "namespace": "crossbar._logging"}) if not isinstance(text, six.text_type): text = text.decode('utf8') print(text, end=record_separator, file=outFile) outFile.flush()