

def compile_context(self, **kwargs):
    if (not hasattr(self, 'fields')):
        self.fields = {k: self.get_field_model(v) for (k, v) in self.__class__.__dict__.items() if ((not k.startswith('_')) and (not isinstance(v, (types.ClassType, types.FunctionType))))}
    missed = ((set(self.fields.keys()) - set(self.get_nullable_fields())) - set(kwargs.keys()))
    if missed:
        raise LoggerError(('Missed fields in event context: %s' % ', '.join(missed)))
    context = {
        
    }
    event_context = get_event_context()
    if event_context:
        event_context.update(event_context)
        username = event_context.get('user_username')
        if (('user' in self.fields) and username):
            logger.warning('User is passed directly to event context. Currently authenticated user %s is ignored.', username)
    for (entity_name, entity) in six.iteritems(kwargs):
        if (entity_name in self.fields):
            entity_class = self.fields[entity_name]
            if ((entity is None) and (entity_name in self.get_nullable_fields())):
                continue
            if (not isinstance(entity, entity_class)):
                raise LoggerError(("Field '%s' must be an instance of %s but %s received" % (entity_name, entity_class.__name__, entity.__class__.__name__)))
        else:
            logger.error("Field '%s' cannot be used in logging context for %s", entity_name, self.__class__.__name__)
            continue
        if isinstance(entity, LoggableMixin):
            context.update(entity._get_log_context(entity_name))
        elif isinstance(entity, (int, float, basestring, dict, tuple, list, bool)):
            context[entity_name] = entity
        elif (entity is None):
            pass
        else:
            context[entity_name] = six.text_type(entity)
            logger.warning(("Cannot properly serialize '%s' context field. Must be inherited from LoggableMixin." % entity_name))
    return context

dataset/ETHPy150Open opennode/nodeconductor/nodeconductor/logging/loggers.py BaseLogger.compile_context/VarMisuse@162/205 `context`->`event_context`