Commit 5e4e39bbb68f0d3d85c8ff6848ab57eb2019c4f7

Authored by hitier
1 parent 5918e302

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,23 +67,21 @@ def create_app(config_class=None):
67 app = Flask(__name__) 67 app = Flask(__name__)
68 app.config.from_object(config_class) 68 app.config.from_object(config_class)
69 69
  70 + # Log to stdout or to file
  71 + #
70 app.logger.removeHandler(default_handler) 72 app.logger.removeHandler(default_handler)
71 -  
72 - # Log to stdout  
73 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']:
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 else: 75 else:
79 logs_file = app.config['PDC_LOGS_FILE'] 76 logs_file = app.config['PDC_LOGS_FILE']
80 logs_dir = os.path.dirname(logs_file) 77 logs_dir = os.path.dirname(logs_file)
81 if not os.path.exists(logs_dir): 78 if not os.path.exists(logs_dir):
82 os.mkdir(logs_dir) 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 app.logger.setLevel(app.config['PDC_LOGS_LEVEL']) 86 app.logger.setLevel(app.config['PDC_LOGS_LEVEL'])
89 app.logger.info("Starting PDC-WEB") 87 app.logger.info("Starting PDC-WEB")
@@ -95,6 +93,7 @@ def create_app(config_class=None): @@ -95,6 +93,7 @@ def create_app(config_class=None):
95 # 93 #
96 from .main import bp as main_bp 94 from .main import bp as main_bp
97 app.register_blueprint(main_bp) 95 app.register_blueprint(main_bp)
  96 +
98 from .auth import bp as auth_bp 97 from .auth import bp as auth_bp
99 app.register_blueprint(auth_bp) 98 app.register_blueprint(auth_bp)
100 99