Skip to content

Commit

Permalink
feat:新增config项is_only_route,默认false,是否忽略记录路由以外的请求,如:404、静态文件请求
Browse files Browse the repository at this point in the history
  • Loading branch information
zodial committed Feb 1, 2023
1 parent e948f6a commit 52fda66
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
20 changes: 17 additions & 3 deletions telescope_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

// Providers @Bean
type Providers struct {
//TODO 默认配置default不生效,config不声明telescope.connect会报错
Mysql *gorm.DB `inject:"mysql, @config(telescope.connect, default)"`
isOpen bool

Expand Down Expand Up @@ -63,9 +64,15 @@ func (t *Providers) AddRoute(v Type) {

// @Bean
type telescopeHook struct {
mysql *gorm.DB
CidToUUID sync.Map
hostname string
mysql *gorm.DB
CidToUUID sync.Map
hostname string
isOnlyRoute bool
}

// TODO 修正不声明config就报错后,可取消这func,改为依赖注入
func (t *telescopeHook) Init() {
t.isOnlyRoute = app.Config("telescope.is_only_route", false)
}

func (t *telescopeHook) Levels() []logrus.Level {
Expand All @@ -78,6 +85,13 @@ func (t *telescopeHook) Fire(entry *logrus.Entry) error {
m = "log"
}
mType := m.(string)
//忽略路由以外的请求
if mType == "request" && t.isOnlyRoute {
ctx := entry.Context.(*gin.Context)
if ctx.FullPath() == "" {
return nil
}
}
route, ok := Routes[mType]
if ok {
telescopeEntries, tags := route.Handler(entry)
Expand Down
27 changes: 18 additions & 9 deletions z_inject_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
gorm "gorm.io/gorm"
)

var _ProvidersSingle *Providers
var _telescopeHookSingle *telescopeHook
var _ProvidersSingle *Providers
var _BatchSingle *Batch
var _CacheSingle *Cache
var _ClientRequestSingle *ClientRequest
Expand All @@ -18,6 +18,7 @@ var _ExceptionSingle *Exception
var _JobSingle *Job
var _LogSingle *Log
var _ModelSingle *Model
var _NotificationSingle *Notification
var _QuerySingle *Query
var _RedisSingle *Redis
var _RequestSingle *Request
Expand All @@ -26,8 +27,8 @@ var _TcpSingle *Tcp

func GetAllProvider() []interface{} {
return []interface{}{
NewProviders(),
NewtelescopeHook(),
NewProviders(),
NewBatch(),
NewCache(),
NewClientRequest(),
Expand All @@ -38,6 +39,7 @@ func GetAllProvider() []interface{} {
NewJob(),
NewLog(),
NewModel(),
NewNotification(),
NewQuery(),
NewRedis(),
NewRequest(),
Expand All @@ -46,6 +48,13 @@ func GetAllProvider() []interface{} {
}
}

func NewtelescopeHook() *telescopeHook {
if _telescopeHookSingle == nil {
_telescopeHookSingle = &telescopeHook{}
providers.AfterProvider(_telescopeHookSingle, "")
}
return _telescopeHookSingle
}
func NewProviders() *Providers {
if _ProvidersSingle == nil {
_ProvidersSingle = &Providers{}
Expand All @@ -54,13 +63,6 @@ func NewProviders() *Providers {
}
return _ProvidersSingle
}
func NewtelescopeHook() *telescopeHook {
if _telescopeHookSingle == nil {
_telescopeHookSingle = &telescopeHook{}
providers.AfterProvider(_telescopeHookSingle, "")
}
return _telescopeHookSingle
}
func NewBatch() *Batch {
if _BatchSingle == nil {
_BatchSingle = &Batch{}
Expand Down Expand Up @@ -131,6 +133,13 @@ func NewModel() *Model {
}
return _ModelSingle
}
func NewNotification() *Notification {
if _NotificationSingle == nil {
_NotificationSingle = &Notification{}
providers.AfterProvider(_NotificationSingle, "")
}
return _NotificationSingle
}
func NewQuery() *Query {
if _QuerySingle == nil {
_QuerySingle = &Query{}
Expand Down

0 comments on commit 52fda66

Please sign in to comment.