Updated gitignore and resolved issues with creating the app
This commit is contained in:
parent
d11fd2ab57
commit
4563f04d84
5
.gitignore
vendored
5
.gitignore
vendored
@ -237,5 +237,8 @@ cython_debug/
|
|||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
.idea/
|
||||||
|
|
||||||
|
# Ignore log files
|
||||||
|
**.log
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ from logging import Logger, Formatter, getLogger, DEBUG, INFO, FileHandler
|
|||||||
|
|
||||||
|
|
||||||
def load_config_from_environ(app: Flask) -> Flask:
|
def load_config_from_environ(app: Flask) -> Flask:
|
||||||
for env_var in os.environ.keys().filter(lambda x: x.startswith(app.name.upper())):
|
for env_var in filter(lambda x: x.startswith(app.name.upper()), os.environ.keys()):
|
||||||
config_name = env_var[len(app.name):]
|
config_name = env_var[len(app.name):]
|
||||||
app.config[config_name] = os.environ[env_var]
|
app.config[config_name] = os.environ[env_var]
|
||||||
|
|
||||||
@ -12,20 +12,22 @@ def load_config_from_environ(app: Flask) -> Flask:
|
|||||||
|
|
||||||
|
|
||||||
def init_logger(app: Flask, log_level=INFO) -> Flask:
|
def init_logger(app: Flask, log_level=INFO) -> Flask:
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(app.name)
|
||||||
formatter = Formatter(f'[%(asctime)s] {app.name.upper()} %(levelname)s: %(message)s (%(filename)s.%(funcName)s)')
|
formatter = Formatter(f'[%(asctime)s] {app.name.upper()} %(levelname)s: %(message)s (%(filename)s.%(funcName)s)')
|
||||||
logger.setFormatter(formatter)
|
|
||||||
logger.setLevel(log_level)
|
logger.setLevel(log_level)
|
||||||
to_file = FileHandler(os.environ.get('APP_LOG_PATH', f'./{app.name}.log'))
|
to_file = FileHandler(os.environ.get('APP_LOG_PATH', f'./{app.name}.log'))
|
||||||
|
to_file.setFormatter(formatter)
|
||||||
logger.addHandler(to_file)
|
logger.addHandler(to_file)
|
||||||
|
|
||||||
app.logger = logger
|
app.logger = logger
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def create_app() -> Flask:
|
def create_app(app_name: str='MRE') -> Flask:
|
||||||
app = Flask(__name__)
|
app = Flask(app_name)
|
||||||
app = load_config_from_environ(app)
|
app = load_config_from_environ(app)
|
||||||
app = init_logger(app)
|
app = init_logger(app)
|
||||||
|
|
||||||
|
app.logger.info(app.name)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user