Skip to content

Commit

Permalink
Merge pull request #368 from askuy/feature/server_http_event_stream
Browse files Browse the repository at this point in the history
非长连接模式下,记入warn慢日志
  • Loading branch information
askuy authored Dec 29, 2023
2 parents 9c0144e + 4bbad09 commit bbbcf25
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions server/egin/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,15 @@ func (c *Container) defaultServerInterceptor() gin.HandlerFunc {

// slow log
if c.config.SlowLogThreshold > time.Duration(0) && c.config.SlowLogThreshold < cost {
// 最后添加状态码
fields = append(fields,
elog.FieldCode(int32(ctx.Writer.Status())),
elog.FieldUniformCode(int32(ctx.Writer.Status())),
)
c.logger.Warn("slow", fields...)
// 非长连接模式下,记入warn慢日志
if ctx.GetHeader("Accept") != "text/event-stream" {
// 最后添加状态码
fields = append(fields,
elog.FieldCode(int32(ctx.Writer.Status())),
elog.FieldUniformCode(int32(ctx.Writer.Status())),
)
c.logger.Warn("slow", fields...)
}
}

if rec := recover(); rec != nil {
Expand Down

0 comments on commit bbbcf25

Please sign in to comment.