def eventsFromJSONLogFile(inFile, recordSeparator=None, bufferSize=4096):
    """
    Load events from a file previously saved with L{jsonFileLogObserver}.
    Event records that are truncated or otherwise unreadable are ignored.

    @param inFile: A (readable) file-like object.  Data read from C{inFile}
        should be L{unicode} or UTF-8 L{bytes}.
    @type inFile: iterable of lines

    @param recordSeparator: The expected record separator.
        If L{None}, attempt to automatically detect the record separator from
        one of C{u"\\x1e"} or C{u""}.
    @type recordSeparator: L{unicode}

    @param bufferSize: The size of the read buffer used while reading from
        C{inFile}.
    @type bufferSize: integer

    @return: Log events as read from C{inFile}.
    @rtype: iterable of L{dict}
    """
    def asBytes(s):
        if type(s) is bytes:
            return s
        else:
            return s.encode("utf-8")

    def eventFromBytearray(record):
        try:
            text = bytes(record).decode("utf-8")
        except UnicodeDecodeError:
            log.error(
                u"Unable to decode UTF-8 for JSON record: {record!r}",
                record=bytes(record)
            )
            return None

        try:
            return eventFromJSON(text)
        except ValueError:
            log.error(
                u"Unable to read JSON record: {record!r}",
                record=bytes(record)
            )
            return None

    if recordSeparator is None:
        first = asBytes(inFile.read(1))

        if first == b"\x1e":
            # This looks json-text-sequence compliant.
            recordSeparator = first
        else:
            # Default to simpler newline-separated stream, which does not use
            # a record separator.
            recordSeparator = b""

    else:
        recordSeparator = asBytes(recordSeparator)
        first = b""

    if recordSeparator == b"":
        recordSeparator = b"\n"  # Split on newlines below

        eventFromRecord = eventFromBytearray

    else:
        def eventFromRecord(record):
            if record[-1] == ord("\n"):
                return eventFromBytearray(record)
            else:
                log.error(
                    u"Unable to read truncated JSON record: {record!r}",
                    record=bytes(record)
                )
            return None

    buffer = bytearray(first)

    while True:
        newData = inFile.read(bufferSize)

        if not newData:
            if len(buffer) > 0:
                event = eventFromRecord(buffer)
                if event is not None:
                    yield event
            break

        buffer += asBytes(newData)
        records = buffer.split(recordSeparator)

        for record in records[:-1]:
            if len(record) > 0:
                event = eventFromRecord(record)
                if event is not None:
                    yield event

        buffer = records[-1]

    Load events from a file previously saved with L{jsonFileLogObserver}.
    Event records that are truncated or otherwise unreadable are ignored.

    @param inFile: A (readable) file-like object.  Data read from C{inFile}
        should be L{unicode} or UTF-8 L{bytes}.
    @type inFile: iterable of lines

    @param recordSeparator: The expected record separator.
        If L{None}, attempt to automatically detect the record separator from
        one of C{u"\x1e"} or C{u""}.
    @type recordSeparator: L{unicode}

    @param bufferSize: The size of the read buffer used while reading from
        C{inFile}.
    @type bufferSize: integer

    @return: Log events as read from C{inFile}.
    @rtype: iterable of L{dict}
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/logger/_json.py