mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-08 15:07:56 +08:00
feat(logging): add file-backed sources for request logging
- Introduced `FileBodySource` to support large request log sections stored in temp files. - Added file-backed support for WebSocket timeline and API WebSocket timeline logging. - Updated `LogRequest` and middleware to integrate optional file-backed sources. - Implemented clean-up mechanisms to manage temporary log files after processing.
This commit is contained in:
@@ -416,6 +416,13 @@ func appendAPIWebsocketTimeline(ginCtx *gin.Context, chunk []byte) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
if source, ok := apiWebsocketTimelineSource(ginCtx); ok {
|
||||
if errAppend := source.AppendPart(data); errAppend == nil {
|
||||
return
|
||||
} else {
|
||||
log.WithError(errAppend).Warn("failed to append api websocket timeline log part")
|
||||
}
|
||||
}
|
||||
if existing, exists := ginCtx.Get(apiWebsocketTimelineKey); exists {
|
||||
if existingBytes, ok := existing.([]byte); ok && len(existingBytes) > 0 {
|
||||
combined := make([]byte, 0, len(existingBytes)+len(data)+2)
|
||||
@@ -432,6 +439,18 @@ func appendAPIWebsocketTimeline(ginCtx *gin.Context, chunk []byte) {
|
||||
ginCtx.Set(apiWebsocketTimelineKey, bytes.Clone(data))
|
||||
}
|
||||
|
||||
func apiWebsocketTimelineSource(ginCtx *gin.Context) (*logging.FileBodySource, bool) {
|
||||
if ginCtx == nil {
|
||||
return nil, false
|
||||
}
|
||||
value, exists := ginCtx.Get(logging.APIWebsocketTimelineSourceContextKey)
|
||||
if !exists {
|
||||
return nil, false
|
||||
}
|
||||
source, ok := value.(*logging.FileBodySource)
|
||||
return source, ok && source != nil
|
||||
}
|
||||
|
||||
func markAPIResponseTimestamp(ginCtx *gin.Context) {
|
||||
if ginCtx == nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user