Skip to content

Commit

Permalink
去除无数据的warning日志
Browse files Browse the repository at this point in the history
如果是error必记录req的请求
  • Loading branch information
askuy committed Jun 27, 2024
1 parent 8f2f451 commit a8e700a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ func accessInterceptor(compName string, c *config, logger *elog.Component) func(
if err != nil {
fields = append(fields, elog.FieldEvent(event), elog.FieldErr(err))
if errors.Is(err, mongo.ErrNoDocuments) {
logger.Warn("access", fields...)
// 这种日志可能很多,也没必要,只有开启的时候,或者慢日志的时候记录
if c.EnableAccessInterceptor || isSlowLog {
logger.Warn("access", fields...)
}
return err
}
// 如果用户没开启req,那么错误必记录Req
if !c.EnableAccessInterceptorReq {
fields = append(fields, elog.Any("req", cmd.req))
}
logger.Error("access", fields...)
return err
}
Expand Down

0 comments on commit a8e700a

Please sign in to comment.