mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
Co-authored-by: Antoine Wacheux <[email protected]> Co-authored-by: Maxence Maireaux <[email protected]> Co-authored-by: Brieuc Caillot <[email protected]>
44 lines
1.0 KiB
Go
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)
|
|
}
|