Commit 5918e30266834b0f2f1ae83720537794948a23ea
1 parent
8105f7da
Exists in
master
and in
4 other branches
Set loglevel from configfile
Showing
1 changed file
with
3 additions
and
7 deletions
Show diff stats
app/__init__.py
@@ -16,7 +16,6 @@ app_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') | @@ -16,7 +16,6 @@ app_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') | ||
16 | env_file = os.path.join(app_dir, ".flaskenv") | 16 | env_file = os.path.join(app_dir, ".flaskenv") |
17 | load_dotenv(env_file, verbose=True) | 17 | load_dotenv(env_file, verbose=True) |
18 | 18 | ||
19 | - | ||
20 | login_manager = LoginManager() | 19 | login_manager = LoginManager() |
21 | 20 | ||
22 | login_manager.login_view = "auth.login" | 21 | login_manager.login_view = "auth.login" |
@@ -70,26 +69,23 @@ def create_app(config_class=None): | @@ -70,26 +69,23 @@ def create_app(config_class=None): | ||
70 | 69 | ||
71 | app.logger.removeHandler(default_handler) | 70 | app.logger.removeHandler(default_handler) |
72 | 71 | ||
73 | - logs_dir = os.path.join(app_dir, 'logs') | ||
74 | - logs_file = os.path.join(logs_dir, 'pdc.log') | ||
75 | - | ||
76 | # Log to stdout | 72 | # Log to stdout |
77 | if app.debug or app.testing or app.config['LOG_TO_STDOUT']: | 73 | if app.debug or app.testing or app.config['LOG_TO_STDOUT']: |
78 | stream_handler = logging.StreamHandler() | 74 | stream_handler = logging.StreamHandler() |
79 | - stream_handler.setLevel(logging.INFO) | ||
80 | app.logger.addHandler(stream_handler) | 75 | app.logger.addHandler(stream_handler) |
81 | # or log to file | 76 | # or log to file |
82 | # TODO: get filename from config | 77 | # TODO: get filename from config |
83 | else: | 78 | else: |
79 | + logs_file = app.config['PDC_LOGS_FILE'] | ||
80 | + logs_dir = os.path.dirname(logs_file) | ||
84 | if not os.path.exists(logs_dir): | 81 | if not os.path.exists(logs_dir): |
85 | os.mkdir(logs_dir) | 82 | os.mkdir(logs_dir) |
86 | file_handler = RotatingFileHandler(logs_file, maxBytes=10240, backupCount=10) | 83 | file_handler = RotatingFileHandler(logs_file, maxBytes=10240, backupCount=10) |
87 | file_handler.setFormatter(logging.Formatter( | 84 | file_handler.setFormatter(logging.Formatter( |
88 | '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) | 85 | '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) |
89 | - file_handler.setLevel(logging.INFO) | ||
90 | app.logger.addHandler(file_handler) | 86 | app.logger.addHandler(file_handler) |
91 | 87 | ||
92 | - app.logger.setLevel(logging.INFO) | 88 | + app.logger.setLevel(app.config['PDC_LOGS_LEVEL']) |
93 | app.logger.info("Starting PDC-WEB") | 89 | app.logger.info("Starting PDC-WEB") |
94 | 90 | ||
95 | db.init_app(app) | 91 | db.init_app(app) |