human
Complete this python program:
def capture(*args, **kw):
assistant
#Here is the Python program you requested.

    """Decorator to wrap an *environment file function* in log file capture.
    It configures the logging capture using the *behave* context - the first
    argument to the function being decorated (so don\t use this to decorate
    something that doesn\t have *context* as the first argument.)
    The basic usage is:
    .. code-block: python
    @capture
    def after_scenario(context, scenario):
    The function prints any captured logging (at the level determined by the
    ``log_level`` configuration setting) directly to stdout, regardless of
    error conditions.
    It is mostly useful for debugging in situations where you are seeing a
    message like::
    No handlers could be found for logger "name"
    The decorator takes an optional "level" keyword argument which limits the
    level of logging captured, overriding the level in the run\s configuration:
    .. code-block: python
    @capture(level=logging.ERROR)
    def after_scenario(context, scenario):
    This would limit the logging captured to just ERROR and above, and thus
    only display logged events if they are interesting.
    """
    def create_decorator(func, level=None):
        def f(context, *args):
            h = LoggingCapture(context.config, level=level)
            h.inveigle()
            try:
                func(context, *args)
            finally:
                h.abandon()
            v = h.getvalue()
            if v:
                print('Captured    Logging:')
                print(v)
        return f
    if (not args):
        return functools.partial(create_decorator, level=kw.get('level'))
    else:
        return create_decorator(args[0])