setup_logging

    Setup logging configuration

    :param default_level: level to log
    :param default_path: path to config (optional)
    :param env_key: path to config in this env var
    :param handler_name: handler name in the config
    :param handlers_dict: handlers dict
    :param log_dict: full log dictionary config
    :param config_name: filename for config
    :param splunk_host: optional splunk host
    :param splunk_port: optional splunk port
    :param splunk_index: optional splunk index
    :param splunk_token: optional splunk token
    :param splunk_verify: optional splunk verify - default to False
    :param splunk_handler_name: optional splunk handler name
    :param splunk_sleep_interval: optional splunk sleep interval
    :param splunk_debug: optional splunk debug - default to False

def setup_logging(
        default_level=logging.INFO,
        default_path=None,
        env_key='LOG_CFG',
        handler_name='console',
        handlers_dict=None,
        log_dict=None,
        config_name=None,
        splunk_host=None,
        splunk_port=None,
        splunk_index=None,
        splunk_token=None,
        splunk_verify=False,
        splunk_handler_name='splunk',
        splunk_sleep_interval=-1,
        splunk_debug=False):
    """setup_logging

    Setup logging configuration

    :param default_level: level to log
    :param default_path: path to config (optional)
    :param env_key: path to config in this env var
    :param handler_name: handler name in the config
    :param handlers_dict: handlers dict
    :param log_dict: full log dictionary config
    :param config_name: filename for config
    :param splunk_host: optional splunk host
    :param splunk_port: optional splunk port
    :param splunk_index: optional splunk index
    :param splunk_token: optional splunk token
    :param splunk_verify: optional splunk verify - default to False
    :param splunk_handler_name: optional splunk handler name
    :param splunk_sleep_interval: optional splunk sleep interval
    :param splunk_debug: optional splunk debug - default to False

    """

    if SPLUNK_DEBUG:
        splunk_debug = True

    if not splunk_token:
        if SPLUNK_TOKEN:
            splunk_token = splunk_token

    config = None
    if os.getenv(
            'LOG_DICT',
            False):
        try:
            config = json.loads(os.getenv(
                'LOG_DICT',
                None).strip())
        except Exception as e:
            print(
                'Please confirm the env key LOG_DICT has a valid '
                'JSON dictionary. Failed json.loads() parsing with '
                '- using default config for '
                'ex={}').format(
                    e)
        # try to parse the dict and log it that there was a failure

    elif log_dict:
        config = config
    # end of if passed in set in an environment variable

    if not config and default_path:
        path = default_path
        file_name = default_path.split('/')[-1]
        if config_name:
            file_name = config_name
        path = '{}/{}'.format(
                    '/'.join(default_path.split('/')[:-1]),
                    file_name)
        value = os.getenv(env_key, None)
        if value:
            path = value
        if os.path.exists(path):
            with open(path, 'rt') as f:
                config = json.load(f)
        else:
            cwd_path = os.getcwd() + '/spylunking/log/{}'.format(
                file_name)
            if os.path.exists(cwd_path):
                with open(cwd_path, 'rt') as f:
                    config = json.load(f)
            else:
                rels_path = os.getcwd() + '/../log/{}'.format(
                    file_name)
                if os.path.exists(rels_path):
                    with open(rels_path, 'rt') as f:
                        config = json.load(f)
                else:
                    repo_config = (
                        '/opt/spylunking/spylunking/log/'
                        'shared-logging.json')
                    if os.path.exists(repo_config):
                        if splunk_debug:
                            print(
                                'checking repo_config={}'.format(
                                    repo_config))
                        with open(repo_config, 'rt') as f:
                            config = json.load(f)
        # end of finding a config dictionary
    # end of trying to find a config on disk

    if config:
        if handlers_dict:
            config['handlers'] = handlers_dict

        found_splunk_handler = False
        if handler_name:
            for hidx, h in enumerate(config['handlers']):
                if splunk_debug:
                    print('handler={} name={}'.format(
                        hidx,
                        h))
                if handler_name == h:
                    config['root']['handlers'].append(h)
                # by default splunk_handler_name == 'splunk'
                if splunk_handler_name == h and splunk_token:
                    found_splunk_handler = True

        if found_splunk_handler:
            if splunk_token:
                config['handlers'][splunk_handler_name]['token'] = \
                    splunk_token
                config['handlers'][splunk_handler_name]['verify'] = \
                    splunk_verify
                if splunk_host:
                    config['handlers'][splunk_handler_name]['host'] = \
                        splunk_host
                if splunk_port:
                    config['handlers'][splunk_handler_name]['port'] = \
                        splunk_port
                if splunk_index:
                    config['handlers'][splunk_handler_name]['index'] = \
                        splunk_index

                config['handlers'][splunk_handler_name]['debug'] = \
                    splunk_debug

                if config['handlers'][splunk_handler_name].get(
                        'queue_size',
                        True):
                    key = 'queue_size'
                    config['handlers'][splunk_handler_name][key] = \
                        SPLUNK_QUEUE_SIZE
                # end of checking for queue_size changes

                if SPLUNK_RETRY_COUNT:
                    key = 'retry_count'
                    config['handlers'][splunk_handler_name][key] = \
                        SPLUNK_RETRY_COUNT
                # end of checking for retry_count changes

                if SPLUNK_TIMEOUT:
                    config['handlers'][splunk_handler_name][key] = \
                        SPLUNK_TIMEOUT
                # end of checking for splunk_timeout changes

                key = 'sleep_interval'
                if splunk_sleep_interval >= 0:
                    config['handlers'][splunk_handler_name][key] = \
                        splunk_sleep_interval
                else:
                    if SPLUNK_SLEEP_INTERVAL:
                        key = 'sleep_interval'
                        config['handlers'][splunk_handler_name][key] = \
                            SPLUNK_SLEEP_INTERVAL

                # end of checking for sleep_interval changes

                if found_splunk_handler:
                    config['root']['handlers'].append(
                        splunk_handler_name)
            else:
                if splunk_debug:
                    print(
                        'Unable to get a valid splunk token '
                        '- splunk disabled')
                config['handlers'].pop('splunk', None)
                good_handlers = []
                for k in config['root']['handlers']:
                    if k != splunk_handler_name:
                        good_handlers.append(k)
                config['root']['handlers'] = good_handlers
        else:
            if splunk_debug:
                print(
                    'splunk disabled')
            config['handlers'].pop(splunk_handler_name, None)
            good_handlers = []
            for k in config['root']['handlers']:
                if k != splunk_handler_name:
                    good_handlers.append(k)
            config['root']['handlers'] = good_handlers

        if len(config['root']['handlers']) == 0:
            print((
                'Failed to find logging root.handlers={} in log '
                'config={}').format(
                    config['root']['handlers'],
                    ppj(config)))
        else:
            if splunk_debug:
                print((
                    'Using log config={}').format(
                        ppj(config)))
        logging.config.dictConfig(
            config)
        return
    else:
        if not splunk_host and not splunk_port:
            if SPLUNK_ADDRESS:
                try:
                    addr_split = SPLUNK_ADDRESS.split(':')
                    if len(addr_split) > 1:
                        splunk_host = addr_split[0]
                        splunk_port = int(addr_split[1])
                except Exception as e:
                    print((
                        'Failed building SPLUNK_ADDRESS={} as'
                        'host:port with ex={}').format(
                            SPLUNK_ADDRESS,
                            e))
        else:
            if not splunk_host:
                if SPLUNK_HOST:
                    splunk_host = SPLUNK_HOST
            if not splunk_port:
                if SPLUNK_PORT:
                    splunk_port = SPLUNK_PORT
        # end of connectivity changes from env vars

        config = {
            'version': 1,
            'disable_existing_loggers': False,
            'formatters': {
                'colors': {
                    '()': 'colorlog.ColoredFormatter',
                    'format': (
                        '%(log_color)s%(asctime)s - %(name)s - '
                        '%(levelname)s - %(message)s%(reset)s')
                },
                'no_date_colors': {
                    '()': 'colorlog.ColoredFormatter',
                    'format': (
                        '%(log_color)s%(name)s - %(levelname)s '
                        '- %(message)s%(reset)s')
                },
                'simple': {
                    '()': 'colorlog.ColoredFormatter',
                    'format': (
                        '%(log_color)s'
                        '%(message)s%(reset)s')
                },
                splunk_handler_name: {
                    '()': 'spylunking.log.setup_logging.SplunkFormatter',
                    'format': (
                        '%(asctime)s - %(name)s - %(levelname)s '
                        '- %(message)s [%(filename)s:%(lineno)s]')
                }
            },
            'handlers': {
                'console': {
                    'class': 'logging.StreamHandler',
                    'level': 'INFO',
                    'formatter': 'colors',
                    'stream': 'ext://sys.stdout'
                },
                'no_date_colors': {
                    'class': 'logging.StreamHandler',
                    'level': 'INFO',
                    'formatter': 'no_date_colors',
                    'stream': 'ext://sys.stdout'
                },
                'simple': {
                    'class': 'logging.StreamHandler',
                    'level': 'INFO',
                    'formatter': 'simple',
                    'stream': 'ext://sys.stdout'
                }
            },
            'loggers': {
                '': {
                    'level': 'INFO',
                    'propagate': True
                }
            },
            'root': {
                'level': 'INFO',
                'propagate': True,
                'handlers': [
                    'console'
                ]
            }
        }
        if splunk_token and splunk_host and splunk_port:
            config['handlers'][splunk_handler_name] = {
                'class': (
                    'spylunking.splunk_publisher.SplunkPublisher'),
                'host': splunk_host,
                'port': splunk_port,
                'index': SPLUNK_INDEX,
                'token': splunk_token,
                'formatter': splunk_handler_name,
                'sourcetype': SPLUNK_SOURCETYPE,
                'verify': SPLUNK_VERIFY,
                'timeout': SPLUNK_TIMEOUT,
                'retry_count': SPLUNK_RETRY_COUNT,
                'sleep_interval': SPLUNK_SLEEP_INTERVAL,
                'queue_size': SPLUNK_QUEUE_SIZE,
                'debug': SPLUNK_DEBUG
            }
            config['root']['handlers'].append(splunk_handler_name)
        # only add splunk if the token is set for HEC
        logging.config.dictConfig(config)
        return