forked from st3v/go-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
52 lines (39 loc) · 1.21 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
package logrus
import (
"github.com/sirupsen/logrus"
"github.com/go-alive/go-micro/logger"
)
type Options struct {
logger.Options
Formatter logrus.Formatter
Hooks logrus.LevelHooks
// Flag for whether to log caller info (off by default)
ReportCaller bool
// Exit Function to call when FatalLevel log
ExitFunc func(int)
}
type formatterKey struct{}
func WithTextTextFormatter(formatter *logrus.TextFormatter) logger.Option {
return logger.SetOption(formatterKey{}, formatter)
}
func WithJSONFormatter(formatter *logrus.JSONFormatter) logger.Option {
return logger.SetOption(formatterKey{}, formatter)
}
type hooksKey struct{}
func WithLevelHooks(hooks logrus.LevelHooks) logger.Option {
return logger.SetOption(hooksKey{}, hooks)
}
type reportCallerKey struct{}
// warning to use this option. because logrus doest not open CallerDepth option
// this will only print this package
func ReportCaller() logger.Option {
return logger.SetOption(reportCallerKey{}, true)
}
type exitKey struct{}
func WithExitFunc(exit func(int)) logger.Option {
return logger.SetOption(exitKey{}, exit)
}
type logrusLoggerKey struct{}
func WithLogger(l logrus.StdLogger) logger.Option {
return logger.SetOption(logrusLoggerKey{}, l)
}