Decorator to log attribute's value(s) before function call.

    Implementation allows usage only for methods belonging to class. The class
    instance needs to have a :attr:`logger` that is derived from
    :py:class:`~creamas.logging.ObjectLogger`.

    :param int level: logging level
    :param str attr: name of the class instance's parameter to be logged

def log_before(attr, level=logging.DEBUG):
    '''Decorator to log attribute's value(s) before function call.

    Implementation allows usage only for methods belonging to class. The class
    instance needs to have a :attr:`logger` that is derived from
    :py:class:`~creamas.logging.ObjectLogger`.

    :param int level: logging level
    :param str attr: name of the class instance's parameter to be logged
    '''
    def deco(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            logger = getattr(args[0], 'logger', None)
            if logger is not None:
                logger.log_attr(level, attr)
            return func(*args, **kwargs)
        return wrapper
    return deco