Files
1641c3c852 feat: update for Ledger v2 (#468)
Co-authored-by: Antoine Wacheux <[email protected]>
Co-authored-by: Maxence Maireaux <[email protected]>
Co-authored-by: Brieuc Caillot <[email protected]>
2023-09-20 16:40:28 +02:00

44 lines
1.0 KiB
Go

package service
import (
"io"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/formancehq/stack/libs/go-libs/otlp/otlptraces"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/uptrace/opentelemetry-go-extra/otellogrus"
)
func GetDefaultLogger(w io.Writer, debug, jsonFormattingLog bool) logging.Logger {
l := logrus.New()
l.SetOutput(w)
if debug {
l.Level = logrus.DebugLevel
}
var formatter logrus.Formatter
if jsonFormattingLog {
jsonFormatter := &logrus.JSONFormatter{}
jsonFormatter.TimestampFormat = "15-01-2018 15:04:05.000000"
formatter = jsonFormatter
} else {
textFormatter := new(logrus.TextFormatter)
textFormatter.TimestampFormat = "15-01-2018 15:04:05.000000"
textFormatter.FullTimestamp = true
formatter = textFormatter
}
l.SetFormatter(formatter)
if viper.GetBool(otlptraces.OtelTracesFlag) {
l.AddHook(otellogrus.NewHook(otellogrus.WithLevels(
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
)))
}
return logging.NewLogrus(l)
}