Beispiel #1
0
    def create_log_record(self, record):
        record = super(SimpleMongoLogHandler, self).create_log_record(record)
        if record['uuid'] == 'none':
            return record
        mongolog_record = LogRecord({
            'name': record['name'],
            'thread': record['thread'],
            'process': record['process'],
            'level': record['levelname'],
            'msg': record['msg'],
            'path': record['pathname'],
            'module': record['module'],
            'line': record['lineno'],
            'func': record['funcName'],
            'filename': record['filename'],
            'uuid': record['uuid'],
            'time': record['time'],
        })

        if record.get('dates'):
            mongolog_record['dates'] = record['dates']

        # Add exception info
        if record['exc_info']:
            mongolog_record['exception'] = {
                'info': record['exc_info'],
                'trace': record['exc_text'].split("\n") if record['exc_text'] else None,
            }
        return mongolog_record
Beispiel #2
0
    def create_log_record(self, record):
        record = super(VerboseMongoLogHandler, self).create_log_record(record)
        mongolog_record = LogRecord({
            'name': record['name'],
            'thread': {
                'num': record['thread'],
                'name': record['threadName'],
            },
            'process': {
                'num': record['process'],
                'name': record['processName'],
            },
            'level': {
                'name': record['levelname'],
                'num': record['levelno'],
            },
            'info': {
                'msg': record['msg'],
                'path': record['pathname'],
                'module': record['module'],
                'line': record['lineno'],
                'func': record['funcName'],
                'filename': record['filename'],
            },
            'uuid': record['uuid'],
            'time': record['time'],
        })

        if record['exc_info']:
            mongolog_record['exception'] = {
                'info': record['exc_info'],
                'trace': record['exc_text'],
            }

        return mongolog_record
Beispiel #3
0
    def create_log_record(self, record):
        """
        Convert the python LogRecord to a MongoLog Record.
        Also add a UUID which is a combination of the log message and log level.

        Override in subclasses to change log record formatting.
        See SimpleMongoLogHandler and VerboseMongoLogHandler
        """
        # This is still a python LogRecord Object that we are manipulating
        if record.exc_info:
            record.exc_text = formatException(record.exc_info)

        record = LogRecord(json.loads(json.dumps(record.__dict__,
                                                 default=str)))
        if "mongolog.management.commands" in record['name']:
            return {
                'uuid': 'none',
                'time': 'none',
                'level': 'MONGOLOG-INTERNAL'
            }
        record = self.check_keys(record)

        # The UUID is a combination of the record.levelname and the record.msg
        if sys.version_info.major >= 3:
            uuid_key = str(record['msg']) + str(record['levelname'])
        else:
            uuid_key = (unicode(record['msg']) +
                        unicode(record['levelname'])).encode(
                            'utf-8', 'replace')

        record.update({
            'uuid':
            uuid.uuid5(uuid_namespace, uuid_key).hex,
            # NOTE: if the user is using django and they have USE_TZ=True in their settings
            # then the timezone displayed will be what is specified in TIME_ZONE
            # For instance if they have TIME_ZONE='UTC' then both dt.now() and dt.utcnow()
            # will be equivalent.
            'time':
            dt.utcnow() if self.time_zone == 'utc' else dt.now(),
        })

        # If we are using an embedded document type
        # we need to create the dates array
        if self.record_type == self.EMBEDDED:
            record['dates'] = [record['time']]

        return record
Beispiel #4
0
    def create_log_record(self, record):
        """
        Convert the python LogRecord to a MongoLog Record.
        Also add a UUID which is a combination of the log message and log level.

        Override in subclasses to change log record formatting.
        See SimpleMongoLogHandler and VerboseMongoLogHandler
        """
        # This is still a python LogRecord Object that we are manipulating
        if record.exc_info:
            record.exc_text = formatException(record.exc_info)

        record = LogRecord(json.loads(json.dumps(record.__dict__, default=str)))
        if "mongolog.management.commands" in record['name']:
            return {'uuid': 'none', 'time': 'none', 'level': 'MONGOLOG-INTERNAL'}
        record = self.check_keys(record)

        # The UUID is a combination of the record.levelname and the record.msg
        if sys.version_info.major >= 3:
            uuid_key = str(record['msg']) + str(record['levelname'])
        else:
            uuid_key = (unicode(record['msg']) + unicode(record['levelname'])).encode('utf-8', 'replace')

        record.update({
            'uuid': uuid.uuid5(uuid_namespace, uuid_key).hex,
            # NOTE: if the user is using django and they have USE_TZ=True in their settings
            # then the timezone displayed will be what is specified in TIME_ZONE
            # For instance if they have TIME_ZONE='UTC' then both dt.now() and dt.utcnow()
            # will be equivalent.
            'time': dt.utcnow() if self.time_zone == 'utc' else dt.now(),
        })

        # If we are using an embedded document type
        # we need to create the dates array
        if self.record_type == self.EMBEDDED:
            record['dates'] = [record['time']]

        return record