Esempio n. 1
0
def setup_logging(app):
    log_formatter = logger.Formatter(
        '%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] %(client)s %(message)s'
    )
    # log to files unless on AppEngine
    if not on_appengine():
        # Main logger
        if not (app.debug or app.config.get('TESTING')):
            handler = logging.FileHandler(
                app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
            handler.setLevel(logging.INFO)
            handler.setFormatter(log_formatter)
            app.logger.addHandler(handler)
        else:
            app.logger.handlers[0].setFormatter(log_formatter)

        # Challenge logger
        handler = logging.FileHandler(
            app.config.get('CHALLENGELOG', '/tmp/scoreboard.challenge.log'))
        handler.setLevel(logging.INFO)
        handler.setFormatter(
            logger.Formatter('%(asctime)s %(client)s %(message)s'))
        local_logger = logging.getLogger('scoreboard')
        local_logger.addHandler(handler)
        app.challenge_log = local_logger
    else:
        app.challenge_log = app.logger
        app.logger.handlers[0].setFormatter(log_formatter)
        logging.getLogger().handlers[0].setFormatter(log_formatter)

    return app
Esempio n. 2
0
def create_app(config=None):
    app = flask.Flask(
        'scoreboard',
        static_folder='../static',
        template_folder='../templates',
    )
    app.config.from_object('scoreboard.config_defaults.Defaults')
    if config is not None:
        app.config.update(**config)
    else:
        app.config.from_object('config')  # Load from config.py

    log_formatter = logger.Formatter(
        '%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] %(client)s %(message)s'
    )
    # log to files unless on AppEngine
    if not on_appengine():
        # Main logger
        if not app.debug:
            handler = logging.FileHandler(
                app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
            handler.setLevel(logging.INFO)
            handler.setFormatter(log_formatter)
            app.logger.addHandler(handler)
        else:
            app.logger.handlers[0].setFormatter(log_formatter)

        # Challenge logger
        handler = logging.FileHandler(
            app.config.get('CHALLENGELOG', '/tmp/scoreboard.challenge.log'))
        handler.setLevel(logging.INFO)
        handler.setFormatter(
            logger.Formatter('%(asctime)s %(client)s %(message)s'))
        logger = logging.getLogger('scoreboard')
        logger.addHandler(handler)
        app.challenge_log = logger
    else:
        app.challenge_log = app.logger
        app.logger.handlers[0].setFormatter(log_formatter)
        logging.getLogger().handlers[0].setFormatter(log_formatter)

    # Install a default error handler
    error_titles = {
        401: 'Unauthorized',
        403: 'Forbidden',
        500: 'Internal Error',
    }
Esempio n. 3
0
        'scoreboard',
        static_folder='../static',
        template_folder='../templates',
        )
app.config.from_object('scoreboard.config_defaults.Defaults')
app.config.from_object('config')  # Load from config.py


def on_appengine():
    """Returns true if we're running on AppEngine."""
    runtime = os.environ.get('SERVER_SOFTWARE', '')
    return (runtime.startswith('Development/') or
            runtime.startswith('Google App Engine/'))


log_formatter = logger.Formatter(
        '%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] %(client)s %(message)s')
# log to files unless on AppEngine
if not on_appengine():
    # Main logger
    if not app.debug:
        handler = logging.FileHandler(
            app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
        handler.setLevel(logging.INFO)
        handler.setFormatter(log_formatter)
        app.logger.addHandler(handler)
    else:
        app.logger.handlers[0].setFormatter(log_formatter)

    # Challenge logger
    handler = logging.FileHandler(
        app.config.get('CHALLENGELOG', '/tmp/scoreboard.challenge.log'))