17 Star 5 Fork 16

openEuler/PilotGo-plugin-topology
关闭

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
logger.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
wubijie 提交于 2024-11-28 10:58 +08:00 . add copyright information
/*
* Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved.
* PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2.
* See LICENSE file for more details.
* Author: Wangjunqi123 <wangjunqi@kylinos.cn>
* Date: Thu Nov 7 16:33:56 2024 +0800
*/
package middleware
import (
"time"
"gitee.com/openeuler/PilotGo-plugin-topology/cmd/server/global"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
func Logger(_skipPaths []string) gin.HandlerFunc {
var skip map[string]struct{}
if len(_skipPaths) > 0 {
skip = make(map[string]struct{}, len(_skipPaths))
for _, path := range _skipPaths {
skip[path] = struct{}{}
}
}
return func(c *gin.Context) {
start := time.Now()
path := c.Request.URL.Path
raw := c.Request.URL.RawQuery
c.Next()
if _, ok := skip[path]; !ok {
endTime := time.Now()
latency := endTime.Sub(start)
method := c.Request.Method
statusCode := c.Writer.Status()
clientIP := c.ClientIP()
errorMessage := c.Errors.ByType(gin.ErrorTypePrivate).String()
if raw != "" {
path = path + "?" + raw
}
if latency > time.Minute {
latency = latency.Truncate(time.Second)
}
global.ERManager.ErrorTransmit("gin", "debug", errors.Errorf("|%3d|%-13v|%-15s|%-7s %#v\n%s",
statusCode,
latency,
clientIP,
method,
path,
errorMessage),
false, false,
)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/PilotGo-plugin-topology.git
git@gitee.com:openeuler/PilotGo-plugin-topology.git
openeuler
PilotGo-plugin-topology
PilotGo-plugin-topology
d8282c0a164a

搜索帮助