代码拉取完成,页面将自动刷新
package api
import (
"gitee.com/sansaniot/ssiot-core/facade/runtime"
"gitee.com/sansaniot/ssiot-core/httpmvc"
"gitee.com/sansaniot/ssiot-core/logger"
"github.com/gin-gonic/gin"
"strings"
)
type loggerKey struct{}
// GetRequestLogger 获取上下文提供的日志
func GetRequestLogger(c *gin.Context) *logger.Helper {
var log *logger.Helper
l, ok := c.Get(httpmvc.LoggerKey)
if ok {
ok = false
log, ok = l.(*logger.Helper)
if ok {
return log
}
}
//如果没有在上下文中放入logger
requestId := httpmvc.GenerateMsgIDFromContext(c)
log = logger.NewHelper(runtime.Runtime.GetLogger()).WithFields(map[string]interface{}{
strings.ToLower(httpmvc.TrafficKey): requestId,
})
return log
}
// SetRequestLogger 设置logger中间件
func SetRequestLogger(c *gin.Context) {
requestId := httpmvc.GenerateMsgIDFromContext(c)
log := logger.NewHelper(runtime.Runtime.GetLogger()).WithFields(map[string]interface{}{
strings.ToLower(httpmvc.TrafficKey): requestId,
})
c.Set(httpmvc.LoggerKey, log)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。