Commit 5e4e39bbb68f0d3d85c8ff6848ab57eb2019c4f7
1 parent
5918e302
Exists in
master
and in
4 other branches
Tiny Code refactor
Showing
1 changed file
with
9 additions
and
10 deletions
Show diff stats
app/__init__.py
... | ... | @@ -67,23 +67,21 @@ def create_app(config_class=None): |
67 | 67 | app = Flask(__name__) |
68 | 68 | app.config.from_object(config_class) |
69 | 69 | |
70 | + # Log to stdout or to file | |
71 | + # | |
70 | 72 | app.logger.removeHandler(default_handler) |
71 | - | |
72 | - # Log to stdout | |
73 | 73 | if app.debug or app.testing or app.config['LOG_TO_STDOUT']: |
74 | - stream_handler = logging.StreamHandler() | |
75 | - app.logger.addHandler(stream_handler) | |
76 | - # or log to file | |
77 | - # TODO: get filename from config | |
74 | + log_handler = logging.StreamHandler() | |
78 | 75 | else: |
79 | 76 | logs_file = app.config['PDC_LOGS_FILE'] |
80 | 77 | logs_dir = os.path.dirname(logs_file) |
81 | 78 | if not os.path.exists(logs_dir): |
82 | 79 | os.mkdir(logs_dir) |
83 | - file_handler = RotatingFileHandler(logs_file, maxBytes=10240, backupCount=10) | |
84 | - file_handler.setFormatter(logging.Formatter( | |
85 | - '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) | |
86 | - app.logger.addHandler(file_handler) | |
80 | + log_handler = RotatingFileHandler(logs_file, maxBytes=10240, backupCount=10) | |
81 | + | |
82 | + log_handler.setFormatter(logging.Formatter( | |
83 | + '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) | |
84 | + app.logger.addHandler(log_handler) | |
87 | 85 | |
88 | 86 | app.logger.setLevel(app.config['PDC_LOGS_LEVEL']) |
89 | 87 | app.logger.info("Starting PDC-WEB") |
... | ... | @@ -95,6 +93,7 @@ def create_app(config_class=None): |
95 | 93 | # |
96 | 94 | from .main import bp as main_bp |
97 | 95 | app.register_blueprint(main_bp) |
96 | + | |
98 | 97 | from .auth import bp as auth_bp |
99 | 98 | app.register_blueprint(auth_bp) |
100 | 99 | ... | ... |