forked from topfreegames/go-workers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkers_logger.go
43 lines (34 loc) · 1008 Bytes
/
workers_logger.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
package workers
import "github.com/sirupsen/logrus"
// WorkersLogger represents the log interface
type WorkersLogger interface {
Fatal(format ...interface{})
Fatalf(format string, args ...interface{})
Fatalln(args ...interface{})
Debug(args ...interface{})
Debugf(format string, args ...interface{})
Debugln(args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
Errorln(args ...interface{})
Info(args ...interface{})
Infof(format string, args ...interface{})
Infoln(args ...interface{})
Warn(args ...interface{})
Warnf(format string, args ...interface{})
Warnln(args ...interface{})
}
// Logger is the default logger
var Logger = initLogger()
func initLogger() WorkersLogger {
plog := logrus.New()
plog.Formatter = new(logrus.TextFormatter)
plog.Level = logrus.InfoLevel
return plog.WithFields(logrus.Fields{"source": "go-workers"})
}
// SetLogger rewrites the default logger
func SetLogger(l WorkersLogger) {
if l != nil {
Logger = l
}
}