From 5918e30266834b0f2f1ae83720537794948a23ea Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Fri, 26 Mar 2021 08:39:15 +0100 Subject: [PATCH] Set loglevel from configfile --- app/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index f4b0d68..0ef65d0 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -16,7 +16,6 @@ app_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') env_file = os.path.join(app_dir, ".flaskenv") load_dotenv(env_file, verbose=True) - login_manager = LoginManager() login_manager.login_view = "auth.login" @@ -70,26 +69,23 @@ def create_app(config_class=None): app.logger.removeHandler(default_handler) - logs_dir = os.path.join(app_dir, 'logs') - logs_file = os.path.join(logs_dir, 'pdc.log') - # Log to stdout if app.debug or app.testing or app.config['LOG_TO_STDOUT']: stream_handler = logging.StreamHandler() - stream_handler.setLevel(logging.INFO) app.logger.addHandler(stream_handler) # or log to file # TODO: get filename from config else: + logs_file = app.config['PDC_LOGS_FILE'] + logs_dir = os.path.dirname(logs_file) if not os.path.exists(logs_dir): os.mkdir(logs_dir) file_handler = RotatingFileHandler(logs_file, maxBytes=10240, backupCount=10) file_handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) - file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) - app.logger.setLevel(logging.INFO) + app.logger.setLevel(app.config['PDC_LOGS_LEVEL']) app.logger.info("Starting PDC-WEB") db.init_app(app) -- libgit2 0.21.2