From 4bbad09e263dce5d8430726da474b6532b7e3310 Mon Sep 17 00:00:00 2001 From: askuy Date: Fri, 29 Dec 2023 22:09:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E9=95=BF=E8=BF=9E=E6=8E=A5=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=EF=BC=8C=E8=AE=B0=E5=85=A5warn=E6=85=A2?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/egin/interceptor.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server/egin/interceptor.go b/server/egin/interceptor.go index 89fe3287..4ceafd33 100644 --- a/server/egin/interceptor.go +++ b/server/egin/interceptor.go @@ -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 {