Commit aa27858a authored by 崔为之's avatar 崔为之 💪🏽

Update project

parent d568fe55
......@@ -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
......@@ -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"
......@@ -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():
......
......@@ -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}')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment