2020-12-09 15:31:34 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Level logrus.Level
|
|
|
|
Formatter logrus.Formatter
|
|
|
|
ReportCaller bool
|
|
|
|
}
|
|
|
|
|
2021-02-10 13:25:07 +00:00
|
|
|
func Init() {
|
|
|
|
config := getConfig()
|
|
|
|
logrus.SetLevel(config.Level)
|
|
|
|
logrus.SetReportCaller(config.ReportCaller)
|
|
|
|
logrus.SetFormatter(config.Formatter)
|
2020-12-09 15:31:34 +00:00
|
|
|
|
|
|
|
// Libs that use logger (like grpc provider) will log at TRACE level
|
|
|
|
redirectLogger := logrus.New()
|
2021-02-10 13:25:07 +00:00
|
|
|
redirectLogger.SetLevel(config.Level)
|
|
|
|
redirectLogger.SetFormatter(config.Formatter)
|
|
|
|
log.SetOutput(redirectLogger.WriterLevel(logrus.TraceLevel))
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|