logger.go
1.0 KB
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
package log
import (
"github.com/linmadan/egglib-go/log"
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
"io"
)
var Logger log.Logger
func init() {
Logger = logrus.NewLogrusLogger()
Logger.SetServiceName(constant.SERVICE_NAME)
Logger.SetLevel(constant.LOG_LEVEL)
}
func InitLogHook(enableKafka bool, enableBeeLog bool) {
if enableKafka {
if w, err := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false); err == nil {
Logger.AddHook(w)
} else {
Logger.Error(err.Error())
}
}
if enableBeeLog {
if w, err := logrus.NewWrapHook(true, func() (io.Writer, error) {
return logrus.NewBeegoLogWriter("", `{"filename":"app.log","maxsize":2048000}`)
}); err == nil {
Logger.AddHook(w)
} else {
Logger.Error(err.Error())
}
}
}
//var Logger *LogrusLogger
//
//func init() {
// Logger = NewLogrusLogger()
// Logger.SetServiceName(constant.SERVICE_NAME)
// Logger.SetLevel(constant.LOG_LEVEL)
//}