Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
aa27858a
Commit
aa27858a
authored
Nov 03, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
d568fe55
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
11 deletions
+18
-11
application/config/config.yaml
application/config/config.yaml
+4
-4
application/lib/flask_loguru/format.py
application/lib/flask_loguru/format.py
+2
-0
application/lib/flask_loguru/logger.py
application/lib/flask_loguru/logger.py
+10
-5
application/utils/dsn/dsn.py
application/utils/dsn/dsn.py
+2
-2
No files found.
application/config/config.yaml
View file @
aa27858a
...
...
@@ -2,8 +2,8 @@ System:
Env
:
public
MySQL
:
U
SER
:
root
P
ASSWORD
:
localhost123
H
OST
:
localhost
P
ORT
:
3306
U
ser
:
root
P
assword
:
localhost123
H
ost
:
localhost
P
ort
:
3306
DB
:
elp
application/lib/flask_loguru/format.py
View file @
aa27858a
...
...
@@ -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
"
application/lib/flask_loguru/logger.py
View file @
aa27858a
...
...
@@ -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
():
...
...
application/utils/dsn/dsn.py
View file @
aa27858a
...
...
@@ -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
.
U
SER
}
:'
f
'
{
app
.
config
.
MySQL
.
P
ASSWORD
}
@
{
app
.
config
.
MySQL
.
HOST
}
:
{
app
.
config
.
MySQL
.
PORT
}
/
{
app
.
config
.
MySQL
.
DB
}
'
)
return
(
f
'mysql+pymysql://
{
app
.
config
.
MySQL
.
U
ser
}
:'
f
'
{
app
.
config
.
MySQL
.
P
assword
}
@
{
app
.
config
.
MySQL
.
Host
}
:
{
app
.
config
.
MySQL
.
Port
}
/
{
app
.
config
.
MySQL
.
DB
}
'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment