Exemplo n.º 1
0
    def __init__(self, fileobj):
        # Check the type explicit here because UnicodeCSVWriter will
        # happy accept a non-file object the fail later.
        if not isinstance(fileobj, file):
            raise TypeError("`fileobj` should be a file")

        self.lock = RLock()
        self.file = fileobj
        self.messages = deque()
        self.lines = 0
        self.csv = UnicodeCSVWriter(self.file)
Exemplo n.º 2
0
class CSVLog(object):
    """
    Internal class which represents a log object and handle
    data that's internal to log handling.
    """
    def __init__(self, fileobj):
        # Check the type explicit here because UnicodeCSVWriter will
        # happy accept a non-file object the fail later.
        if not isinstance(fileobj, file):
            raise TypeError("`fileobj` should be a file")

        self.lock = RLock()
        self.file = fileobj
        self.messages = deque()
        self.lines = 0
        self.csv = UnicodeCSVWriter(self.file)

    def write(self, data):
        """Writes the given data to the underlying csv object."""
        date, streamno, lineno, pid, message = data
        self.csv.writerow(
            [date.isoformat(), str(streamno), str(lineno), str(pid), message])