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
26fd5be2
Commit
26fd5be2
authored
Nov 21, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
187a55b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
7 deletions
+26
-7
application/views/log/__init__.py
application/views/log/__init__.py
+11
-1
application/views/log/log.py
application/views/log/log.py
+15
-6
No files found.
application/views/log/__init__.py
View file @
26fd5be2
...
@@ -7,12 +7,22 @@
...
@@ -7,12 +7,22 @@
# @Email : StudentCWZ@outlook.com
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/19 16:05
# @Date : 2023/11/19 16:05
# @File : __init__.py
# @File : __init__.py
# @Description :
# @Description :
Registers the logging views with the Flask application.
"""
"""
from
flask
import
Flask
from
flask
import
Flask
from
.log
import
log_api
from
.log
import
log_api
def
register_log_views
(
app
:
Flask
):
def
register_log_views
(
app
:
Flask
):
"""
Registers the log API blueprint with the Flask application.
Args:
app (Flask): The Flask application.
Returns:
None
"""
app
.
register_blueprint
(
log_api
)
app
.
register_blueprint
(
log_api
)
application/views/log/log.py
View file @
26fd5be2
...
@@ -7,10 +7,10 @@
...
@@ -7,10 +7,10 @@
# @Email : StudentCWZ@outlook.com
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/19 16:05
# @Date : 2023/11/19 16:05
# @File : log.py
# @File : log.py
# @Description :
# @Description :
Defines the log API endpoints.
"""
"""
from
flask
import
Blueprint
,
current_app
,
request
,
jsonify
from
flask
import
Blueprint
,
jsonify
,
request
from
flask_restful
import
Api
from
flask_restful
import
Api
from
loguru
import
logger
from
loguru
import
logger
from
pydantic
import
ValidationError
from
pydantic
import
ValidationError
...
@@ -19,24 +19,33 @@ from application.schemas import ParseLogRequestItem
...
@@ -19,24 +19,33 @@ from application.schemas import ParseLogRequestItem
from
application.services
import
LogService
from
application.services
import
LogService
# Define the log API blueprint
log_api
=
Blueprint
(
'log_api'
,
__name__
)
log_api
=
Blueprint
(
'log_api'
,
__name__
)
api_logs
=
Api
(
log_api
)
api_logs
=
Api
(
log_api
)
@
log_api
.
route
(
'/logs'
,
methods
=
[
'POST'
])
@
log_api
.
route
(
'/logs'
,
methods
=
[
'POST'
])
def
parse
():
def
parse
():
"""
Parses the logs based on the request.
Returns:
The total number of logs parsed or an error message if the input data is invalid.
"""
json_data
=
request
.
get_json
(
force
=
True
)
json_data
=
request
.
get_json
(
force
=
True
)
# If no data provided, return error message
if
not
json_data
:
if
not
json_data
:
logger
.
error
(
'No input data provided'
)
logger
.
error
(
'No input data provided'
)
return
jsonify
({
"message"
:
"No input data provided"
}),
400
return
jsonify
({
"message"
:
"No input data provided"
}),
400
try
:
try
:
# Validate input data
item
=
ParseLogRequestItem
(
**
json_data
)
item
=
ParseLogRequestItem
(
**
json_data
)
except
ValidationError
as
e
:
except
ValidationError
as
e
:
# If validation fails, return error message
return
jsonify
({
"message"
:
"Invalid input data"
,
"errors"
:
e
.
errors
()}),
400
return
jsonify
({
"message"
:
"Invalid input data"
,
"errors"
:
e
.
errors
()}),
400
# If validation passes, parse logs and return total number of logs parsed
total
=
LogService
.
parse
(
item
)
total
=
LogService
.
parse
(
item
)
return
jsonify
(
return
jsonify
(
search_total
=
total
),
200
search_total
=
total
),
200
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