Exemplo n.º 1
0
 def _write(self, msg):
     # all output should be encoded in utf-8
     # to be correctly written to file or terminal
     # in presence of international characters
     text = force_text(msg + '\n')
     encoded = text.encode('utf-8')
     self.stream.write(encoded)
Exemplo n.º 2
0
 def _write(self, msg):
     # all output should be encoded in utf-8
     # to be correctly written to file or terminal
     # in presence of international characters
     text = force_text(msg + '\n')
     encoded = text.encode('utf-8')
     self.stream.write(encoded)
Exemplo n.º 3
0
 def get_log_entry(msg, timestamp, source_host, fields):
     return {
         '@message': force_text(msg.text),
         '@timestamp': timestamp.isoformat(),
         '@source_host': source_host,
         '@fields': fields,
     }
Exemplo n.º 4
0
 def get_log_entry(msg, timestamp, source_host, fields):
     return {
         '@message': force_text(msg.text),
         '@timestamp': timestamp.isoformat(),
         '@source_host': source_host,
         '@fields': fields,
     }
Exemplo n.º 5
0
    def format(self, msg, source_host=None):
        if source_host is None:
            source_host = socket.gethostname()

        fields = msg.fields.copy()
        fields['level'] = get_log_level_str(fields['level'])
        timestamp = fields.pop('time')
        timestamp = datetime.datetime.utcfromtimestamp(calendar.timegm(timestamp))
        timestamp = timestamp.replace(tzinfo=pytz.utc)

        if msg.traceback:
            fields['exception'] = force_text(msg.traceback)

        for key, value in fields.items():
            if not isinstance(value, NUMERIC_TYPES):
                if isinstance(value, six.string_types):
                    fields[key] = force_text(value)
                else:
                    fields[key] = six.text_type(value)

        return self.get_log_entry(msg, timestamp, source_host, fields)
Exemplo n.º 6
0
    def format(self, msg, source_host=None):
        if source_host is None:
            source_host = socket.gethostname()

        fields = msg.fields.copy()
        fields['level'] = get_log_level_str(fields['level'])
        timestamp = fields.pop('time')
        timestamp = datetime.datetime.utcfromtimestamp(calendar.timegm(timestamp))
        timestamp = timestamp.replace(tzinfo=pytz.utc)

        if msg.traceback:
            fields['exception'] = force_text(msg.traceback)

        for key, value in fields.items():
            if not isinstance(value, (int, float)):
                if isinstance(value, six.string_types):
                    fields[key] = force_text(value)
                else:
                    fields[key] = six.text_type(value)

        return self.get_log_entry(msg, timestamp, source_host, fields)
Exemplo n.º 7
0
    def process_item(value):
        if not isinstance(value, NUMERIC_TYPES):
            if isinstance(value, six.string_types):
                # encode utf-8 to unicode, if necessary
                return force_text(value)
            else:
                if isinstance(value, dict):
                    return prepare_fields(value)
                elif isinstance(value, list):
                    return list(map(process_item, value))

                return six.text_type(value)
        return value
Exemplo n.º 8
0
    def process_item(value):
        if not isinstance(value, NUMERIC_TYPES):
            if isinstance(value, six.string_types):
                # encode utf-8 to unicode, if necessary
                return force_text(value)
            else:
                if isinstance(value, dict):
                    return prepare_fields(value)
                elif isinstance(value, list):
                    return list(map(process_item, value))

                return six.text_type(value)
        return value
Exemplo n.º 9
0
    def format(self, msg, source_host=None):
        if source_host is None:
            source_host = socket.gethostname()

        fields = msg.fields.copy()
        fields['level'] = get_log_level_str(fields['level'])
        timestamp = fields.pop('time')
        timestamp = datetime.datetime.utcfromtimestamp(calendar.timegm(timestamp))
        timestamp = timestamp.replace(tzinfo=pytz.utc)

        if msg.traceback:
            fields['exception'] = force_text(msg.traceback)

        fields = prepare_fields(fields)
        return self.get_log_entry(msg, timestamp, source_host, fields)
Exemplo n.º 10
0
    def format(self, msg, source_host=None):
        if source_host is None:
            source_host = socket.gethostname()

        fields = msg.fields.copy()
        fields['level'] = get_log_level_str(fields['level'])
        timestamp = fields.pop('time')
        timestamp = datetime.datetime.utcfromtimestamp(
            calendar.timegm(timestamp))
        timestamp = timestamp.replace(tzinfo=pytz.utc)

        if msg.traceback:
            fields['exception'] = force_text(msg.traceback)

        fields = prepare_fields(fields)
        return self.get_log_entry(msg, timestamp, source_host, fields)
Exemplo n.º 11
0
 def _write(self, msg):
     self.stream.write(force_text(msg + '\n'))
Exemplo n.º 12
0
 def _write(self, msg):
     self.stream.write(force_text(msg + '\n'))