forked from SierraSoftworks/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreadcrumb.go
62 lines (50 loc) · 1.63 KB
/
breadcrumb.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package sentry
import "time"
// A Breadcrumb keeps track of an action which took place in the application
// leading up to an event.
type Breadcrumb interface {
// WithMessage sets the message displayed for this breadcrumb
WithMessage(msg string) Breadcrumb
// WithCategory sets the category that this breadcrumb belongs to
WithCategory(cat string) Breadcrumb
// Level sets the severity level of this breadcrumb to one of the
// predefined severity levels.
WithLevel(s Severity) Breadcrumb
// WithTimestamp overrides the timestamp of this breadcrumb with
// a new one.
WithTimestamp(ts time.Time) Breadcrumb
}
func newBreadcrumb(typename string, data map[string]interface{}) *breadcrumb {
if typename == "default" {
typename = ""
}
return &breadcrumb{
Timestamp: time.Now().UTC().Unix(),
Type: typename,
Data: data,
}
}
type breadcrumb struct {
Timestamp int64 `json:"timestamp"`
Type string `json:"type,omitempty"`
Message string `json:"message,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
Category string `json:"category,omitempty"`
Level Severity `json:"level,omitempty"`
}
func (b *breadcrumb) WithMessage(msg string) Breadcrumb {
b.Message = msg
return b
}
func (b *breadcrumb) WithCategory(cat string) Breadcrumb {
b.Category = cat
return b
}
func (b *breadcrumb) WithTimestamp(ts time.Time) Breadcrumb {
b.Timestamp = ts.UTC().Unix()
return b
}
func (b *breadcrumb) WithLevel(s Severity) Breadcrumb {
b.Level = s
return b
}