def bark_filter(global_conf, **local_conf):
    """
    Factory function for Bark.  Returns a function which, when passed
    the application, returns an instance of BarkMiddleware.

    :param global_conf: The global configuration, from the [DEFAULT]
                        section of the PasteDeploy configuration file.
    :param local_conf: The local configuration, from the filter
                       section of the PasteDeploy configuration file.
    """

    # First, parse the configuration
    conf_file = None
    sections = {}
    for key, value in local_conf.items():
        # 'config' key causes a load of a configuration file; settings
        # in the local_conf will override settings in the
        # configuration file, however
        if key == 'config':
            conf_file = value
        elif '.' in key:
            sect, _sep, opt = key.partition('.')
            sect_dict = sections.setdefault(sect, {})
            sect_dict[opt] = value  # note: a string

    # Now that we've loaded local_conf, process conf_file (if any)
    if conf_file:
        cp = ConfigParser.SafeConfigParser()
        cp.read([conf_file])
        for sect in cp.sections():
            for opt, value in cp.options(sect):
                sect_dict = sections.setdefault(sect, {})
                # By using setdefault(), we allow local_conf to
                # override the configuration file
                sect_dict.setdefault(opt, value)

    # OK, the configuration is all read; next step is to turn the
    # configuration into logging handlers
    handlers = {}
    proxies = None
    for sect, sect_dict in sections.items():
        if sect == 'proxies':
            # Reserved for proxy configuration
            try:
                proxies = bark.proxy.ProxyConfig(sect_dict)
            except KeyError as exc:
                LOG.warn("Cannot configure proxy handling: option %s is "
                         "missing from the proxy configuration" % exc)
            continue  # Pragma: nocover

        # First, determine the logging format
        try:
            format = bark.format.Format.parse(sect_dict.pop('format'))
        except KeyError:
            LOG.warn("No format specified for log %r; skipping." % sect)
            continue

        # Next, determine the handler type
        handle_type = sect_dict.pop('type', 'file')

        # Now, let's construct a handler; this will be a callable
        # taking the formatted message to log
        try:
            handler = bark.handlers.get_handler(handle_type, sect, sect_dict)
        except Exception as exc:
            LOG.warn("Cannot load handler of type %r for log %r: %s" %
                     (handle_type, sect, exc))
            continue

        # We now have a handler and a format; bundle them up
        handlers[sect] = (format, handler)

    # Construct the wrapper which is going to instantiate the
    # middleware
    def wrapper(app):
        return BarkMiddleware(app, handlers, proxies)

    return wrapper
Factory function for Bark.  Returns a function which, when passed
    the application, returns an instance of BarkMiddleware.

    :param global_conf: The global configuration, from the [DEFAULT]
                        section of the PasteDeploy configuration file.
    :param local_conf: The local configuration, from the filter
                       section of the PasteDeploy configuration file.