<commit_before># -*- coding: utf-8 -*-
"""The app module, containing the app factory function."""

import sys
import logging

from flask import Flask, render_template

from feedback.settings import ProductionConfig
from feedback.assets import assets, test_assets
from feedback.extensions import (
    db, ma, login_manager,
    migrate, debug_toolbar,
    cache
)
from feedback.utils import thispage

from feedback import (
    public, user,
    dashboard, surveys
)

login_manager.login_view = "public.login"


def create_app(config_object=ProductionConfig):
    """An application factory, as explained here:
        http://flask.pocoo.org/docs/patterns/appfactories/
    :param config_object: The configuration object to use.
    """
    app = Flask(__name__)
    app.config.from_object(config_object)
    register_extensions(app)
    register_blueprints(app)
    register_errorhandlers(app)
    register_logging(app)
    register_jinja_extensions(app)

    @app.before_first_request
    def before_first_request():

        if app.config.get('ENV') == 'stage':
            stdout = logging.StreamHandler(sys.stdout)
            stdout.setFormatter(logging.Formatter(
            '''-------------------------------
        %(asctime)s | %(name)s | %(levelname)s in %(module)s: %(message)s'''))
            app.logger.addHandler(stdout)
            app.logger.setLevel(logging.DEBUG)

        elif app.debug and not app.testing:
            # log to console for dev
            app.logger.setLevel(logging.DEBUG)
        elif app.testing:
            # disable logging output
            app.logger.setLevel(logging.CRITICAL)
        else:
            # for heroku, just send everything to the console (instead of a file)
            # and it will forward automatically to the logging service

            stdout = logging.StreamHandler(sys.stdout)
            stdout.setFormatter(logging.Formatter(
                '%(asctime)s | %(name)s | %(levelname)s in %(module)s [%(pathname)s:%(lineno)d]: %(message)s'
            ))
            app.logger.addHandler(stdout)
            app.logger.setLevel(logging.DEBUG)
    return app


def register_extensions(app):
    test_assets.init_app(app) if app.config.get('TESTING') else assets.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db)
    assets.init_app(app)
    cache.init_app(app)
    debug_toolbar.init_app(app)
    return None


def register_blueprints(app):
    app.register_blueprint(public.views.blueprint)
    app.register_blueprint(user.views.blueprint)
    app.register_blueprint(dashboard.views.blueprint)
    # app.register_blueprint(surveys.views.blueprint)
    return None


def register_jinja_extensions(app):
    app.jinja_env.globals['thispage'] = thispage
    return None


def register_errorhandlers(app):
    def render_error(error):
        # If a HTTPException, pull the `code` attribute; default to 500
        error_code = getattr(error, 'code', 500)

        return render_template("{0}.html".format(error_code))

    for errcode in [401, 404, 500]:
        app.errorhandler(errcode)(render_error)
    return None


def register_logging(app):
    app.logger.removeHandler(app.logger.handlers[0])
    app.logger.setLevel(logging.DEBUG)
    stdout = logging.StreamHandler(sys.stdout)
    stdout.setFormatter(logging.Formatter(
    '''-------------------------------
%(asctime)s | %(name)s | %(levelname)s in %(module)s: %(message)s'''))
    app.logger.addHandler(stdout)
    return None
<commit_msg>HOTFIX HEROKU<commit_after># -*- coding: utf-8 -*-
"""The app module, containing the app factory function."""

import sys
import logging

from flask import Flask, render_template

from feedback.settings import ProductionConfig
from feedback.assets import assets, test_assets
from feedback.extensions import (
    db, ma, login_manager,
    migrate, debug_toolbar,
    cache
)
from feedback.utils import thispage

from feedback import (
    public, user,
    dashboard
)

login_manager.login_view = "public.login"


def create_app(config_object=ProductionConfig):
    """An application factory, as explained here:
        http://flask.pocoo.org/docs/patterns/appfactories/
    :param config_object: The configuration object to use.
    """
    app = Flask(__name__)
    app.config.from_object(config_object)
    register_extensions(app)
    register_blueprints(app)
    register_errorhandlers(app)
    register_logging(app)
    register_jinja_extensions(app)

    @app.before_first_request
    def before_first_request():

        if app.config.get('ENV') == 'stage':
            stdout = logging.StreamHandler(sys.stdout)
            stdout.setFormatter(logging.Formatter(
            '''-------------------------------
        %(asctime)s | %(name)s | %(levelname)s in %(module)s: %(message)s'''))
            app.logger.addHandler(stdout)
            app.logger.setLevel(logging.DEBUG)

        elif app.debug and not app.testing:
            # log to console for dev
            app.logger.setLevel(logging.DEBUG)
        elif app.testing:
            # disable logging output
            app.logger.setLevel(logging.CRITICAL)
        else:
            # for heroku, just send everything to the console (instead of a file)
            # and it will forward automatically to the logging service

            stdout = logging.StreamHandler(sys.stdout)
            stdout.setFormatter(logging.Formatter(
                '%(asctime)s | %(name)s | %(levelname)s in %(module)s [%(pathname)s:%(lineno)d]: %(message)s'
            ))
            app.logger.addHandler(stdout)
            app.logger.setLevel(logging.DEBUG)
    return app


def register_extensions(app):
    test_assets.init_app(app) if app.config.get('TESTING') else assets.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db)
    assets.init_app(app)
    cache.init_app(app)
    debug_toolbar.init_app(app)
    return None


def register_blueprints(app):
    app.register_blueprint(public.views.blueprint)
    app.register_blueprint(user.views.blueprint)
    app.register_blueprint(dashboard.views.blueprint)
    # app.register_blueprint(surveys.views.blueprint)
    return None


def register_jinja_extensions(app):
    app.jinja_env.globals['thispage'] = thispage
    return None


def register_errorhandlers(app):
    def render_error(error):
        # If a HTTPException, pull the `code` attribute; default to 500
        error_code = getattr(error, 'code', 500)

        return render_template("{0}.html".format(error_code))

    for errcode in [401, 404, 500]:
        app.errorhandler(errcode)(render_error)
    return None


def register_logging(app):
    app.logger.removeHandler(app.logger.handlers[0])
    app.logger.setLevel(logging.DEBUG)
    stdout = logging.StreamHandler(sys.stdout)
    stdout.setFormatter(logging.Formatter(
    '''-------------------------------
%(asctime)s | %(name)s | %(levelname)s in %(module)s: %(message)s'''))
    app.logger.addHandler(stdout)
    return None

{'fraction_non_alphanumeric': 0.12491158579714245, 'fraction_numerical': 0.00509265808459471, 'mean_word_length': 2.951928451648966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '178815', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2107, 'n_words': 442}