<commit_before>from __future__ import print_function, absolute_import, unicode_literals, division

import sys

from alppaca.assume_role import AssumedRoleCredentialsProvider
from alppaca.ims_interface import IMSCredentialsProvider
from alppaca.scheduler import Scheduler
from alppaca.webapp import WebApp
from alppaca.util import setup_logging
from alppaca.compat import OrderedDict


def run_scheduler_and_webserver(config):
    logging_config = None
    try:
        logger = setup_logging(config)
    except Exception:
        print("Could not setup logging with config '{0}'".format(
            logging_config), file=sys.stderr)
        raise
    try:
        # Credentials is a shared object that connects the scheduler and the
        # bottle_app. The scheduler writes into it and the bottle_app reads
        # from it.
        credentials = OrderedDict()
        # initialize the credentials provider
        ims_host_port = '%s:%s' % (config['ims_host'], config['ims_port'])
        ims_protocol = config.get('ims_protocol', 'https')
        credentials_provider = IMSCredentialsProvider(ims_host_port, ims_protocol=ims_protocol)

        role_to_assume = config.get('assume_role')
        if role_to_assume:
            credentials_provider = AssumedRoleCredentialsProvider(
                credentials_provider,
                role_to_assume,
                config.get('aws_proxy_host'),
                config.get('aws_proxy_port')
            )

        Scheduler(credentials, credentials_provider).refresh_credentials()
        # initialize and run the web app
        bind_ip = config.get('bind_ip', '127.0.0.1')
        bind_port = config.get('bind_port', '25772')
        webapp = WebApp(credentials)
        webapp.run(host=bind_ip, port=bind_port)
    except Exception:
        logger.exception("Cannot start Alppaca")<commit_msg>CLOUD-257 #15 Add proper logging for main application<commit_after>from __future__ import print_function, absolute_import, unicode_literals, division

import sys

from alppaca.assume_role import AssumedRoleCredentialsProvider
from alppaca.ims_interface import IMSCredentialsProvider
from alppaca.scheduler import Scheduler
from alppaca.webapp import WebApp
from alppaca.util import setup_logging
from alppaca.compat import OrderedDict


def run_scheduler_and_webserver(config):
    logging_config = None
    try:
        logger = setup_logging(config)
    except Exception:
        print("Could not setup logging with config '{0}'".format(
            logging_config), file=sys.stderr)
        raise
    logger.info("Alppaca starting up...")
    try:
        # Credentials is a shared object that connects the scheduler and the
        # bottle_app. The scheduler writes into it and the bottle_app reads
        # from it.
        credentials = OrderedDict()
        # initialize the credentials provider
        ims_host_port = '%s:%s' % (config['ims_host'], config['ims_port'])
        ims_protocol = config.get('ims_protocol', 'https')
        logger.info("Will get credentials from %s using %s", ims_host_port, ims_protocol)
        credentials_provider = IMSCredentialsProvider(ims_host_port, ims_protocol=ims_protocol)

        role_to_assume = config.get('assume_role')
        if role_to_assume:
            logger.info("Option assume_role set to '%s'", role_to_assume)
            credentials_provider = AssumedRoleCredentialsProvider(
                credentials_provider,
                role_to_assume,
                config.get('aws_proxy_host'),
                config.get('aws_proxy_port')
            )

        Scheduler(credentials, credentials_provider).refresh_credentials()
        # initialize and run the web app
        bind_ip = config.get('bind_ip', '127.0.0.1')
        bind_port = config.get('bind_port', '25772')
        logger.debug("Starting webserver on %s:%s", bind_ip, bind_port)
        webapp = WebApp(credentials)
        webapp.run(host=bind_ip, port=bind_port)
    except Exception:
        logger.exception("Error in Alppaca")
    finally:
        logger.info("Alppaca shutting down...")
{'fraction_non_alphanumeric': 0.08159764763538349, 'fraction_numerical': 0.007106101445724087, 'mean_word_length': 3.1149193548387095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6321792', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1141, 'n_words': 284}