forked from icco/logrus-stackdriver-formatter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
97 lines (81 loc) · 2.19 KB
/
options.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package logadapter
import (
"encoding/hex"
"github.com/gofrs/uuid"
)
type StackTraceStyle int
const (
TraceInMessage StackTraceStyle = iota
TraceInPayload
TraceInBoth
)
// Option lets you configure the Formatter.
type Option func(*Formatter)
// WithService lets you configure the service name used for error reporting.
func WithService(n string) Option {
return func(f *Formatter) {
f.Service = n
}
}
// WithVersion lets you configure the service version used for error reporting.
func WithVersion(v string) Option {
return func(f *Formatter) {
f.Version = v
}
}
// WithSourceReference adds reference to the source code.
func WithSourceReference(repository, revision string) Option {
return func(f *Formatter) {
f.SourceReference = append(f.SourceReference, SourceReference{
Repository: repository,
RevisionID: revision,
})
}
}
// WithProjectID makes sure all entries have your Project information.
func WithProjectID(i string) Option {
return func(f *Formatter) {
f.ProjectID = i
}
}
// WithStackSkip lets you configure which packages should be skipped for locating the error.
func WithStackSkip(v string) Option {
return func(f *Formatter) {
f.StackSkip = append(f.StackSkip, v)
}
}
// WithRegexSkip lets you configure
// which functions or packages should be skipped for locating the error.
func WithRegexSkip(v string) Option {
return func(f *Formatter) {
f.RegexSkip = v
}
}
// WithSkipTimestamp lets you avoid setting the timestamp
func WithSkipTimestamp() Option {
return func(f *Formatter) {
f.SkipTimestamp = true
}
}
// WithStackTraceStyle configures where to write the stacktrace:
// appended to the message, as its own field, or both
func WithStackTraceStyle(s StackTraceStyle) Option {
return func(f *Formatter) {
f.StackStyle = s
}
}
// WithPrettyPrint pretty-prints logs.
func WithPrettyPrint() Option {
return func(f *Formatter) {
f.PrettyPrint = true
}
}
// WithGlobalTraceID sets a consistent trace id on the global logger context
// If not provided, a random id will be generated at runtime
func WithGlobalTraceID(id uuid.UUID) Option {
return func(f *Formatter) {
buf := make([]byte, 32)
hex.Encode(buf, id.Bytes())
f.GlobalTraceID = string(buf)
}
}