Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3570bc2d
authored
Feb 04, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: log search field request_id
parent
163bcb4c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
6 deletions
+35
-6
controller/log.go
+4
-2
model/log.go
+11
-2
web/src/components/table/usage-logs/UsageLogsFilters.jsx
+9
-0
web/src/hooks/usage-logs/useUsageLogsData.jsx
+11
-2
No files found.
controller/log.go
View file @
3570bc2d
...
...
@@ -20,7 +20,8 @@ func GetAllLogs(c *gin.Context) {
modelName
:=
c
.
Query
(
"model_name"
)
channel
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"channel"
))
group
:=
c
.
Query
(
"group"
)
logs
,
total
,
err
:=
model
.
GetAllLogs
(
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
username
,
tokenName
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
(),
channel
,
group
)
requestId
:=
c
.
Query
(
"request_id"
)
logs
,
total
,
err
:=
model
.
GetAllLogs
(
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
username
,
tokenName
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
(),
channel
,
group
,
requestId
)
if
err
!=
nil
{
common
.
ApiError
(
c
,
err
)
return
...
...
@@ -40,7 +41,8 @@ func GetUserLogs(c *gin.Context) {
tokenName
:=
c
.
Query
(
"token_name"
)
modelName
:=
c
.
Query
(
"model_name"
)
group
:=
c
.
Query
(
"group"
)
logs
,
total
,
err
:=
model
.
GetUserLogs
(
userId
,
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
tokenName
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
(),
group
)
requestId
:=
c
.
Query
(
"request_id"
)
logs
,
total
,
err
:=
model
.
GetUserLogs
(
userId
,
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
tokenName
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
(),
group
,
requestId
)
if
err
!=
nil
{
common
.
ApiError
(
c
,
err
)
return
...
...
model/log.go
View file @
3570bc2d
...
...
@@ -36,6 +36,7 @@ type Log struct {
TokenId
int
`json:"token_id" gorm:"default:0;index"`
Group
string
`json:"group" gorm:"index"`
Ip
string
`json:"ip" gorm:"index;default:''"`
RequestId
string
`json:"request_id,omitempty" gorm:"type:varchar(64);index:idx_logs_request_id;default:''"`
Other
string
`json:"other"`
}
...
...
@@ -132,6 +133,7 @@ func RecordErrorLog(c *gin.Context, userId int, channelId int, modelName string,
}
return
""
}(),
RequestId
:
c
.
GetString
(
common
.
RequestIdKey
),
Other
:
otherStr
,
}
err
:=
LOG_DB
.
Create
(
log
)
.
Error
...
...
@@ -191,6 +193,7 @@ func RecordConsumeLog(c *gin.Context, userId int, params RecordConsumeLogParams)
}
return
""
}(),
RequestId
:
c
.
GetString
(
common
.
RequestIdKey
),
Other
:
otherStr
,
}
err
:=
LOG_DB
.
Create
(
log
)
.
Error
...
...
@@ -204,7 +207,7 @@ func RecordConsumeLog(c *gin.Context, userId int, params RecordConsumeLogParams)
}
}
func
GetAllLogs
(
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
username
string
,
tokenName
string
,
startIdx
int
,
num
int
,
channel
int
,
group
string
)
(
logs
[]
*
Log
,
total
int64
,
err
error
)
{
func
GetAllLogs
(
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
username
string
,
tokenName
string
,
startIdx
int
,
num
int
,
channel
int
,
group
string
,
requestId
string
)
(
logs
[]
*
Log
,
total
int64
,
err
error
)
{
var
tx
*
gorm
.
DB
if
logType
==
LogTypeUnknown
{
tx
=
LOG_DB
...
...
@@ -221,6 +224,9 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
if
tokenName
!=
""
{
tx
=
tx
.
Where
(
"logs.token_name = ?"
,
tokenName
)
}
if
requestId
!=
""
{
tx
=
tx
.
Where
(
"logs.request_id = ?"
,
requestId
)
}
if
startTimestamp
!=
0
{
tx
=
tx
.
Where
(
"logs.created_at >= ?"
,
startTimestamp
)
}
...
...
@@ -269,7 +275,7 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
return
logs
,
total
,
err
}
func
GetUserLogs
(
userId
int
,
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
tokenName
string
,
startIdx
int
,
num
int
,
group
string
)
(
logs
[]
*
Log
,
total
int64
,
err
error
)
{
func
GetUserLogs
(
userId
int
,
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
tokenName
string
,
startIdx
int
,
num
int
,
group
string
,
requestId
string
)
(
logs
[]
*
Log
,
total
int64
,
err
error
)
{
var
tx
*
gorm
.
DB
if
logType
==
LogTypeUnknown
{
tx
=
LOG_DB
.
Where
(
"logs.user_id = ?"
,
userId
)
...
...
@@ -283,6 +289,9 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
if
tokenName
!=
""
{
tx
=
tx
.
Where
(
"logs.token_name = ?"
,
tokenName
)
}
if
requestId
!=
""
{
tx
=
tx
.
Where
(
"logs.request_id = ?"
,
requestId
)
}
if
startTimestamp
!=
0
{
tx
=
tx
.
Where
(
"logs.created_at >= ?"
,
startTimestamp
)
}
...
...
web/src/components/table/usage-logs/UsageLogsFilters.jsx
View file @
3570bc2d
...
...
@@ -93,6 +93,15 @@ const LogsFilters = ({
size=
'small'
/>
<
Form
.
Input
field=
'request_id'
prefix=
{
<
IconSearch
/>
}
placeholder=
{
t
(
'Request ID'
)
}
showClear
pure
size=
'small'
/>
{
isAdminUser
&&
(
<>
<
Form
.
Input
...
...
web/src/hooks/usage-logs/useUsageLogsData.jsx
View file @
3570bc2d
...
...
@@ -94,6 +94,7 @@ export const useLogsData = () => {
model_name
:
''
,
channel
:
''
,
group
:
''
,
request_id
:
''
,
dateRange
:
[
timestamp2string
(
getTodayStartTimestamp
()),
timestamp2string
(
now
.
getTime
()
/
1000
+
3600
),
...
...
@@ -230,6 +231,7 @@ export const useLogsData = () => {
end_timestamp
,
channel
:
formValues
.
channel
||
''
,
group
:
formValues
.
group
||
''
,
request_id
:
formValues
.
request_id
||
''
,
logType
:
formValues
.
logType
?
parseInt
(
formValues
.
logType
)
:
0
,
};
};
...
...
@@ -348,6 +350,12 @@ export const useLogsData = () => {
value
:
`
${
logs
[
i
].
channel
}
-
${
logs
[
i
].
channel_name
||
'[未知]'
}
`
,
});
}
if
(
logs
[
i
].
request_id
)
{
expandDataLocal
.
push
({
key
:
t
(
'Request ID'
),
value
:
logs
[
i
].
request_id
,
});
}
if
(
other
?.
ws
||
other
?.
audio
)
{
expandDataLocal
.
push
({
key
:
t
(
'语音输入'
),
...
...
@@ -620,6 +628,7 @@ export const useLogsData = () => {
end_timestamp
,
channel
,
group
,
request_id
,
logType
:
formLogType
,
}
=
getFormValues
();
...
...
@@ -633,9 +642,9 @@ export const useLogsData = () => {
let
localStartTimestamp
=
Date
.
parse
(
start_timestamp
)
/
1000
;
let
localEndTimestamp
=
Date
.
parse
(
end_timestamp
)
/
1000
;
if
(
isAdminUser
)
{
url
=
`/api/log/?p=
${
startIdx
}
&page_size=
${
pageSize
}
&type=
${
currentLogType
}
&username=
${
username
}
&token_name=
${
token_name
}
&model_name=
${
model_name
}
&start_timestamp=
${
localStartTimestamp
}
&end_timestamp=
${
localEndTimestamp
}
&channel=
${
channel
}
&group=
${
group
}
`
;
url
=
`/api/log/?p=
${
startIdx
}
&page_size=
${
pageSize
}
&type=
${
currentLogType
}
&username=
${
username
}
&token_name=
${
token_name
}
&model_name=
${
model_name
}
&start_timestamp=
${
localStartTimestamp
}
&end_timestamp=
${
localEndTimestamp
}
&channel=
${
channel
}
&group=
${
group
}
&request_id=
${
request_id
}
`
;
}
else
{
url
=
`/api/log/self/?p=
${
startIdx
}
&page_size=
${
pageSize
}
&type=
${
currentLogType
}
&token_name=
${
token_name
}
&model_name=
${
model_name
}
&start_timestamp=
${
localStartTimestamp
}
&end_timestamp=
${
localEndTimestamp
}
&group=
${
group
}
`
;
url
=
`/api/log/self/?p=
${
startIdx
}
&page_size=
${
pageSize
}
&type=
${
currentLogType
}
&token_name=
${
token_name
}
&model_name=
${
model_name
}
&start_timestamp=
${
localStartTimestamp
}
&end_timestamp=
${
localEndTimestamp
}
&group=
${
group
}
&request_id=
${
request_id
}
`
;
}
url
=
encodeURI
(
url
);
const
res
=
await
API
.
get
(
url
);
...
...
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