예제 #1
0
def init_logger(app):
    log_format = config.get('app', 'LOG_FORMAT')
    log_root_level = config.get('app', 'LOG_ROOT_LEVEL')
    log_file_path = config.get('app', 'LOG_FILE_PATH')
    log_file_log_level = config.get('app', 'LOG_FILE_LOG_LEVEL')
    init_flask_logger(app, log_format, log_root_level, log_file_path,
                      log_file_log_level)

    if config.getboolean('app', 'DEBUG'):
        app.logger.addHandler(logging.StreamHandler(sys.stderr))
예제 #2
0
def switch_engine(new_engine=None, test=False):
    global engine
    global DBSession
    extra_args = {}
    is_sqlite = DB_URL.startswith("sqlite")
    is_debug = config.getboolean("db", "debug")
    if not is_sqlite:
        extra_args = {"pool_size": 100, "max_overflow": 0}
    if new_engine is None:
        if test:
            new_engine = create_engine(DB_URL_TEST, echo=is_debug)
        else:
            new_engine = create_engine(DB_URL, echo=is_debug, **extra_args)

    engine = new_engine
    DBSession = sessionmaker(bind=engine)
예제 #3
0
def init_app_config(app, config):
    class CFG(object):
        pass

    cfg = CFG()
    for name in config.options('app'):
        setattr(cfg, name.upper(), config.get('app', name))

    cfg.PORT = config.getint('app', 'PORT')
    cfg.HOST = config.get('app', 'HOST')
    cfg.SQLALCHEMY_DATABASE_URI = config.get('db', 'SQLALCHEMY_DATABASE_URI')
    cfg.MAX_CONTENT_LENGTH = config.getint('app', 'MAX_CONTENT_LENGTH')
    cfg.DEBUG = config.getboolean('app', 'DEBUG')
    server_name = os.getenv('ORANGEAPP_SERVER_URL', '')
    if server_name:
        cfg.SERVER_NAME = server_name
        config.set('app', 'SERVER_NAME', server_name)

    app.config.from_object(cfg)