Skip to content

Commit

Permalink
fix: 非指针函数以致无法获取hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
zodial committed May 23, 2023
1 parent 2328d03 commit 97b508b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions type_exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Exception struct {
Occurrences int `json:"occurrences"`
}

func (b Exception) BindType() string {
func (b *Exception) BindType() string {
return "exception"
}

Expand All @@ -32,15 +32,15 @@ type trace struct {
Line string `json:"line"`
}

// 切割标识, 这个标识以后的代码才是业务的
// ExceptionSplit 切割标识, 这个标识以后的代码才是业务的
var ExceptionSplit = "github.com/sirupsen/logrus/"

func (b Exception) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Exception) Handler(entry *logrus.Entry) (*entries, []tag) {
strStack := entry.Data["stack"].(string)
return b.ToSave(strStack, entry.Message)
}

func (b Exception) ToSave(strStack, msg string) (*entries, []tag) {
func (b *Exception) ToSave(strStack, msg string) (*entries, []tag) {
b.Message = msg
b.Trace = make([]trace, 0)
b.LinePreview = make(map[int]string)
Expand Down
6 changes: 3 additions & 3 deletions type_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Job struct {
Hostname string `json:"hostname"`
}

func (b Job) Boot() {
func (b *Job) Boot() {
if app2.IsDebug() && app.HasBean("queue") {
server := app.GetBean("queue").(*servers.Queue)
server.AddMiddleware(func(job constraint.Job, next func(constraint.Job)) {
Expand All @@ -45,11 +45,11 @@ func (b Job) Boot() {
}
}

func (b Job) BindType() string {
func (b *Job) BindType() string {
return "job"
}

func (b Job) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Job) Handler(entry *logrus.Entry) (*entries, []tag) {
b.Name = entry.Message
b.Data = entry.Data["data"]
b.Status = entry.Data["status"].(string)
Expand Down
10 changes: 5 additions & 5 deletions type_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ type Log struct {
Context map[string]interface{} `json:"context"`
}

func (b Log) BindType() string {
func (b *Log) BindType() string {
return "log"
}

func (b Log) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Log) Handler(entry *logrus.Entry) (*entries, []tag) {
if entry.Level <= logrus.ErrorLevel {
defer func() {
telescopeEntries, tags := NewException().ToSave(string(debug.Stack()), entry.Message)
Expand All @@ -29,17 +29,17 @@ func (b Log) Handler(entry *logrus.Entry) (*entries, []tag) {
b.Message = entry.Message
b.Context = entry.Data
b.Level = entry.Level.String()
uuid := uuid.NewV4().String()
id := uuid.NewV4().String()
return &entries{
Uuid: uuid,
Uuid: id,
BatchId: NewtelescopeHook().TelescopeUUID(),
FamilyHash: nil,
ShouldDisplayOnIndex: 1,
Type: b.BindType(),
Content: ToContent(b),
CreatedAt: time.Now().Format("2006-01-02 15:04:05"),
}, []tag{{
EntryUuid: uuid,
EntryUuid: id,
Tag: b.Level,
}}
}
10 changes: 5 additions & 5 deletions type_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ type Query struct {
Hostname string `json:"hostname"`
}

func (b Query) Init() {
func (b *Query) Init() {
b.Hostname, _ = os.Hostname()
}

func (b Query) BindType() string {
func (b *Query) BindType() string {
return "query"
}

// QuerySplit 切割标识, 这个标识以后的代码才是业务的
var QuerySplit = "/app/entity/"

func (b Query) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Query) Handler(entry *logrus.Entry) (*entries, []tag) {
if strings.Index(entry.Message, "telescope_") != -1 {
return nil, nil
}
Expand Down Expand Up @@ -70,9 +70,9 @@ func (b Query) Handler(entry *logrus.Entry) (*entries, []tag) {
b.File, b.Line = GetStackCallFile(stack, "go-home-admin/home/bootstrap/services/logs/mysql")
}

uuid := uuid.NewV4().String()
id := uuid.NewV4().String()
return &entries{
Uuid: uuid,
Uuid: id,
BatchId: NewtelescopeHook().TelescopeUUID(),
FamilyHash: nil,
ShouldDisplayOnIndex: 1,
Expand Down
4 changes: 2 additions & 2 deletions type_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ type Redis struct {
Hostname string `json:"hostname"`
}

func (b Redis) BindType() string {
func (b *Redis) BindType() string {
return "redis"
}

// RedisSplit 切割标识, 这个标识以后的代码才是业务的
var RedisSplit = "github.com/sirupsen/logrus/"

func (b Redis) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Redis) Handler(entry *logrus.Entry) (*entries, []tag) {
file, line := GetStackCallFile(string(debug.Stack()), RedisSplit)

b.Connection = file + ":" + line
Expand Down
6 changes: 3 additions & 3 deletions type_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ type Request struct {
Hostname string `json:"hostname,omitempty"`
}

func (b Request) Init() {
func (b *Request) Init() {
b.Hostname, _ = os.Hostname()
}

func (b Request) BindType() string {
func (b *Request) BindType() string {
return "request"
}

func (b Request) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Request) Handler(entry *logrus.Entry) (*entries, []tag) {
b.Payload = make(map[string]interface{})

uuId := uuid.NewV4().String()
Expand Down
4 changes: 2 additions & 2 deletions type_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ type Schedule struct {
Hostname string `json:"hostname"`
}

func (b Schedule) BindType() string {
func (b *Schedule) BindType() string {
return "schedule"
}

func (b Schedule) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Schedule) Handler(entry *logrus.Entry) (*entries, []tag) {
b.Command = entry.Message
return &entries{
Uuid: uuid.NewV4().String(),
Expand Down
4 changes: 2 additions & 2 deletions type_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ type Tcp struct {
Hostname string `json:"hostname,omitempty"`
}

func (b Tcp) BindType() string {
func (b *Tcp) BindType() string {
return "tcp"
}

// Handler
// logrus.WithFields(logrus.Fields{"type": "tcp","read": raw,"tags": []string{str}}).Debug(tpc_route)
func (b Tcp) Handler(entry *logrus.Entry) (*entries, []tag) {
func (b *Tcp) Handler(entry *logrus.Entry) (*entries, []tag) {
ip, ok := entry.Data["ip"]
if ok {
b.IpAddress = ip.(string)
Expand Down

0 comments on commit 97b508b

Please sign in to comment.