-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistrar.go
48 lines (37 loc) · 1.07 KB
/
registrar.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 logruskit
import (
"github.com/sirupsen/logrus"
"io"
)
// FormatterFunc should use to define new formatter.
type FormatterFunc func(config Config) (logrus.Formatter, error)
// HookFunc should use to define new hook.
type HookFunc func(config Config) (logrus.Hook, error)
// OutputFunc is function to use for defining new outputs.
type OutputFunc func(config Config) (io.Writer, error)
var (
formatters = make(map[string]FormatterFunc)
hooks = make(map[string]HookFunc)
outputs = make(map[string]OutputFunc)
)
// RegisterOutput register writer.
func RegisterOutput(name string, fn OutputFunc) {
outputs[name] = fn
}
// RegisterFormatter function register new formatter.
func RegisterFormatter(name string, fn FormatterFunc) {
formatters[name] = fn
}
// RegisterHook function register new hook.
func RegisterHook(name string, fn HookFunc) {
hooks[name] = fn
}
func getFormatter(name string) FormatterFunc {
return formatters[name]
}
func getHook(name string) HookFunc {
return hooks[name]
}
func getOutput(name string) OutputFunc {
return outputs[name]
}