mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 10:09:54 +08:00
v2.0
This commit is contained in:
37
server/internal/logic/hook/global_log.go
Normal file
37
server/internal/logic/hook/global_log.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Package hook
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package hook
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
// GlobalLog 全局日志
|
||||
func (s *sHook) GlobalLog(r *ghttp.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
)
|
||||
|
||||
// 没有上下文的请求不记录,如:doc、favicon.ico等非功能类业务
|
||||
modelCtx := contexts.Get(ctx)
|
||||
if modelCtx == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 计算运行耗时
|
||||
contexts.SetTakeUpTime(ctx, gtime.TimestampMilli()-r.EnterTime)
|
||||
|
||||
go func() {
|
||||
if err := service.SysLog().AutoLog(ctx); err != nil {
|
||||
g.Log().Info(ctx, "GlobalLog AutoLog err:", err)
|
||||
}
|
||||
}()
|
||||
}
|
22
server/internal/logic/hook/init.go
Normal file
22
server/internal/logic/hook/init.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Package hook
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package hook
|
||||
|
||||
import (
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
type sHook struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterHook(New())
|
||||
}
|
||||
|
||||
func New() *sHook {
|
||||
return &sHook{}
|
||||
}
|
Reference in New Issue
Block a user