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:
Luis Pater
2026-05-25 21:55:16 +08:00
parent 412d3442fa
commit a0bb1f3a2b
8 changed files with 892 additions and 40 deletions

View File

@@ -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