logger.go 1.0 KB
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)
//}