-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_log.go
48 lines (42 loc) · 1.11 KB
/
type_log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package telescope
import (
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"runtime/debug"
"time"
)
// Log @Bean
type Log struct {
Level string `json:"level,omitempty"`
Message string `json:"message"`
Context map[string]interface{} `json:"context"`
}
func (l *Log) BindType() string {
return "log"
}
func (l *Log) Handler(entry *logrus.Entry) (*entries, []tag) {
b := *l
if entry.Level <= logrus.ErrorLevel {
hasError = true
defer func() {
telescopeEntries, tags := NewException().ToSave(string(debug.Stack()), entry.Message)
NewtelescopeHook().Save(telescopeEntries, tags)
}()
}
b.Message = entry.Message
b.Context = entry.Data
b.Level = entry.Level.String()
id := uuid.NewV4().String()
return &entries{
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: id,
Tag: b.Level,
}}
}