Set the debug level which limits the severity of log messages printed by ``pf(4)``.

    level:
        Log level. Should be one of the following: emerg, alert, crit, err, warning, notice,
        info or debug (OpenBSD); or none, urgent, misc, loud (FreeBSD).

    CLI example:

    .. code-block:: bash

        salt '*' pf.loglevel emerg

def loglevel(level):
    '''
    Set the debug level which limits the severity of log messages printed by ``pf(4)``.

    level:
        Log level. Should be one of the following: emerg, alert, crit, err, warning, notice,
        info or debug (OpenBSD); or none, urgent, misc, loud (FreeBSD).

    CLI example:

    .. code-block:: bash

        salt '*' pf.loglevel emerg
    '''
    # There's no way to getting the previous loglevel so imply we've
    # always made a change.
    ret = {'changes': True}

    myos = __grains__['os']
    if myos == 'FreeBSD':
        all_levels = ['none', 'urgent', 'misc', 'loud']
    else:
        all_levels = ['emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug']
    if level not in all_levels:
        raise SaltInvocationError('Unknown loglevel: {0}'.format(level))

    result = __salt__['cmd.run_all']('pfctl -x {0}'.format(level),
                                     output_loglevel='trace',
                                     python_shell=False)

    if result['retcode'] != 0:
        raise CommandExecutionError(
            'Problem encountered setting loglevel',
            info={'errors': [result['stderr']], 'changes': False}
        )

    return ret