-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
53 lines (45 loc) · 1.53 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
package rollrus
import "github.com/sirupsen/logrus"
// OptionFunc that can be passed to NewHook.
type OptionFunc func(*Hook)
// WithLevels is an OptionFunc that customizes the log.Levels the hook will
// report on.
func WithLevels(levels ...logrus.Level) OptionFunc {
return func(h *Hook) {
h.triggers = levels
}
}
// WithMinLevel is an OptionFunc that customizes the log.Levels the hook will
// report on by selecting all levels more severe than the one provided.
func WithMinLevel(level logrus.Level) OptionFunc {
var levels []logrus.Level
for _, l := range logrus.AllLevels {
if l <= level {
levels = append(levels, l)
}
}
return func(h *Hook) {
h.triggers = levels
}
}
// WithIgnoredErrors is an OptionFunc that whitelists certain errors to prevent
// them from firing. See https://golang.org/ref/spec#Comparison_operators
func WithIgnoredErrors(errors ...error) OptionFunc {
return func(h *Hook) {
h.ignoredErrors = append(h.ignoredErrors, errors...)
}
}
// WithIgnoreErrorFunc is an OptionFunc that receives the error that is about
// to be logged and returns true/false if it wants to fire a Rollbar alert for.
func WithIgnoreErrorFunc(fn func(error) bool) OptionFunc {
return func(h *Hook) {
h.ignoreErrorFunc = fn
}
}
// WithIgnoreFunc is an OptionFunc that receives the error and custom fields that are about
// to be logged and returns true/false if it wants to fire a Rollbar alert for.
func WithIgnoreFunc(fn func(err error, fields map[string]interface{}) bool) OptionFunc {
return func(h *Hook) {
h.ignoreFunc = fn
}
}