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

Update project

parent d568fe55
...@@ -2,8 +2,8 @@ System: ...@@ -2,8 +2,8 @@ System:
Env: public Env: public
MySQL: MySQL:
USER: root User: root
PASSWORD: localhost123 Password: localhost123
HOST: localhost Host: localhost
PORT: 3306 Port: 3306
DB: elp DB: elp
...@@ -14,6 +14,7 @@ import json ...@@ -14,6 +14,7 @@ import json
def serialize(record: dict) -> str: def serialize(record: dict) -> str:
"""Customize logger format"""
time_stamp = record["time"] time_stamp = record["time"]
time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S") time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
subset = { subset = {
...@@ -27,5 +28,6 @@ def serialize(record: dict) -> str: ...@@ -27,5 +28,6 @@ def serialize(record: dict) -> str:
def patching(record: dict) -> str: def patching(record: dict) -> str:
"""Set the patch"""
record["extra"]["serialized"] = serialize(record) record["extra"]["serialized"] = serialize(record)
return "{extra[serialized]}\n" return "{extra[serialized]}\n"
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# @Description : # @Description :
""" """
import os
import sys import sys
from flask import Flask, request, g from flask import Flask, request, g
...@@ -23,14 +24,18 @@ class FlaskLoguru: ...@@ -23,14 +24,18 @@ class FlaskLoguru:
if app is not None: if app is not None:
self.init_app(app) self.init_app(app)
def init_app(self, app: Flask): def init_app(self, app: Flask) -> None:
"""Initialize the app"""
logger.remove() 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 = {}
app.extensions.setdefault("loguru", {}) app.extensions.setdefault('loguru', {})
app.extensions["loguru"][self] = logger app.extensions['loguru'][self] = logger
@app.before_request @app.before_request
def before_request(): def before_request():
......
...@@ -23,5 +23,5 @@ def dsn(app: Flask) -> str: ...@@ -23,5 +23,5 @@ def dsn(app: Flask) -> str:
mysql_cfg = app.config.get('MySQL') mysql_cfg = app.config.get('MySQL')
if mysql_cfg is None: if mysql_cfg is None:
raise KeyError('Key MySQL error') raise KeyError('Key MySQL error')
return (f'mysql+pymysql://{app.config.MySQL.USER}:' 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}') 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