def log(message=None, out=sys.stdout):
    """Log a message before passing through to the wrapped function.

    This is useful if you want to determine whether wrappers are
    passing down the pipeline to the functions they wrap, or exiting
    early, usually with some kind of exception.

    Example:
    example_view = decorate(username_matches_request_user,
                            log("The username matched"),
                            json_api_call,
                            example)
    """
    def decorator(view_fn):
        @wraps(view_fn)
        def f(*args, **kwargs):
            print(message, file=out)
            return view_fn(*args, **kwargs)
        return f
    return decorator
Log a message before passing through to the wrapped function.

    This is useful if you want to determine whether wrappers are
    passing down the pipeline to the functions they wrap, or exiting
    early, usually with some kind of exception.

    Example:
    example_view = decorate(username_matches_request_user,
                            log("The username matched"),
                            json_api_call,
                            example)