Ejemplo n.º 1
0
    def format(self, record):
        """docstring for format"""
        rec = dict(vars(record))
        rec.update(self.static_fields)

        created = datetime.datetime.utcfromtimestamp(rec.pop('created'))
        data = dict(
            message=record.getMessage(),
            level=SYSLOG_LEVELS.get(record.levelno, record.levelno),
            time=datetime.datetime.strftime(created, self.default_datefmt)
        )

        # we removed args
        rec.pop('args')

        for attr, value in rec.items():
            if attr in self.default_fields.keys():
                key = self.default_fields[attr]
            else:
                key = attr
            if isinstance(value, (STRING_TYPE, float) + INTEGER_TYPE):
                data[key] = value
            elif value is None:
                data[key] = ""
            else:
                data[key] = repr(value)

        out = "\t".join(['%s:%s' %i for i in data.items()])
        if self.null_character == True:
            out += '\0'
        return out
Ejemplo n.º 2
0
    def format(self, record):
        """docstring for format"""
        rec = dict(vars(record))
        rec.update(**self.static_fields)
        data = dict(
            version="1.1",
            host=self.hostname,
            short_message=record.getMessage(),
            level=SYSLOG_LEVELS.get(rec.pop('levelno')),
        )

        # we removed args
        rec.pop('args')

        for attr, value in rec.items():
            if attr in self.default_fields.keys():
                key = self.default_fields[attr]
            else:
                key = "_%s" % attr
            check_str = isinstance(value, (STRING_TYPE, float) + INTEGER_TYPE)
            if check_str or value is None:
                data[key] = value
            else:
                try:
                    data[key] = repr(value)
                except:
                    pass

        out = json.dumps(data)
        if self.null_character == True:
            out += '\0'
        return out
Ejemplo n.º 3
0
    def format(self, record):
        data = dict(
            message=record.getMessage(),
            level=SYSLOG_LEVELS.get(record.levelno, record.levelno),
            time=datetime.datetime.strftime(record.timestamp, self.default_datefmt),
            instance=record.instance)

        for name, value in chain(self.static_fields.iteritems(), record.extra.iteritems()):
            data[name] = escape(value)

        result = "\t".join(["%s:%s" % item for item in data.iteritems()])
        if self.null_character:
            result += "\0"
        return result
Ejemplo n.º 4
0
    def format(self, record):
        data = dict(
            version="1.1",
            host=self.hostname,
            short_message=record.getMessage(),
            level=SYSLOG_LEVELS.get(record.levelno),
            timestamp=(record.timestamp - UNIX_ORIGIN).total_seconds(),
            _instance=record.instance)

        for name, value in chain(self.static_fields.iteritems(), record.extra.iteritems()):
            data["_%s" % name] = escape(value)

        result = json.dumps(data)
        if self.null_character:
            result += "\0"
        return result