diff --git a/application/config/config.yaml b/application/config/config.yaml index 483103214f3885677c598db86a2aed59352aed24..6c967a5113478872a2febecb2def82991e64ffd0 100644 --- a/application/config/config.yaml +++ b/application/config/config.yaml @@ -2,8 +2,8 @@ System: Env: public MySQL: - USER: root - PASSWORD: localhost123 - HOST: localhost - PORT: 3306 + User: root + Password: localhost123 + Host: localhost + Port: 3306 DB: elp diff --git a/application/lib/flask_loguru/format.py b/application/lib/flask_loguru/format.py index ca5fe95d59eedb9482d6d589b29956b1eb1907dc..a24227c2b1b82a009c4d8715bf2cc8887fa6252a 100644 --- a/application/lib/flask_loguru/format.py +++ b/application/lib/flask_loguru/format.py @@ -14,6 +14,7 @@ import json def serialize(record: dict) -> str: + """Customize logger format""" time_stamp = record["time"] time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S") subset = { @@ -27,5 +28,6 @@ def serialize(record: dict) -> str: def patching(record: dict) -> str: + """Set the patch""" record["extra"]["serialized"] = serialize(record) return "{extra[serialized]}\n" diff --git a/application/lib/flask_loguru/logger.py b/application/lib/flask_loguru/logger.py index 6b015d54d3ce4befad7bfeb36dcdd6c5eab87108..fd7ff8b272fccf4831c889fce6b5ca6c2df7300f 100644 --- a/application/lib/flask_loguru/logger.py +++ b/application/lib/flask_loguru/logger.py @@ -10,6 +10,7 @@ # @Description : """ +import os import sys from flask import Flask, request, g @@ -23,14 +24,18 @@ class FlaskLoguru: if app is not None: self.init_app(app) - def init_app(self, app: Flask): + def init_app(self, app: Flask) -> None: + """Initialize the app""" logger.remove() - logger.add(sys.stderr, format=patching) - if not hasattr(app, "extensions"): + # 获取日志级别 + level = app.config.Logger.Level if app.config.get('Logger') is not None else 'DEBUG' + logger.add(sys.stderr, level=level, format=patching) + # 注册扩展 + if not hasattr(app, 'extensions'): app.extensions = {} - app.extensions.setdefault("loguru", {}) - app.extensions["loguru"][self] = logger + app.extensions.setdefault('loguru', {}) + app.extensions['loguru'][self] = logger @app.before_request def before_request(): diff --git a/application/utils/dsn/dsn.py b/application/utils/dsn/dsn.py index 0f7b544ca5ffba9322928c9b9f0997b614dff25b..87937cfbde0865080e894f5ef14652ae84ae984f 100644 --- a/application/utils/dsn/dsn.py +++ b/application/utils/dsn/dsn.py @@ -23,5 +23,5 @@ def dsn(app: Flask) -> str: mysql_cfg = app.config.get('MySQL') if mysql_cfg is None: raise KeyError('Key MySQL error') - return (f'mysql+pymysql://{app.config.MySQL.USER}:' - f'{app.config.MySQL.PASSWORD}@{app.config.MySQL.HOST}:{app.config.MySQL.PORT}/{app.config.MySQL.DB}') + return (f'mysql+pymysql://{app.config.MySQL.User}:' + f'{app.config.MySQL.Password}@{app.config.MySQL.Host}:{app.config.MySQL.Port}/{app.config.MySQL.DB}')