diff --git a/logrus/adapter.go b/logrus/adapter.go new file mode 100644 index 0000000..46300e1 --- /dev/null +++ b/logrus/adapter.go @@ -0,0 +1,52 @@ +package logrusadapter + +import ( + "github.com/graphmetrics/logger-go" + "github.com/graphmetrics/logger-go/options" + "github.com/sirupsen/logrus" +) + +type logrusAdapter struct { + parent *logrus.Logger +} + +func New(parent *logrus.Logger) logger.Logger { + return &logrusAdapter{parent: parent} +} + +func (z *logrusAdapter) Debug(msg string, metadata map[string]interface{}) { + entry := z.parent.WithFields(metadata) + entry.Debug(msg) +} + +func (z *logrusAdapter) Info(msg string, metadata map[string]interface{}) { + entry := z.parent.WithFields(metadata) + entry.Info(msg) +} + +func (z *logrusAdapter) Warn(msg string, metadata map[string]interface{}) { + entry := z.parent.WithFields(metadata) + entry.Warn(msg) +} + +func (z *logrusAdapter) Error(msg string, metadata map[string]interface{}) { + entry := z.parent.WithFields(metadata) + entry.Error(msg) +} + +func (z *logrusAdapter) WithOptions(opts ...options.LoggerOption) logger.Logger { + adapter := z + for _, o := range opts { + switch o.Parameter() { + case "CallerSkipOffset": + // Waiting on https://github.com/sirupsen/logrus/pull/1215 otherwise the caller is overriden anyway + break + case "Named": + // Loggers don't have names + break + default: + break + } + } + return adapter +} diff --git a/logrus/go.mod b/logrus/go.mod new file mode 100644 index 0000000..742d689 --- /dev/null +++ b/logrus/go.mod @@ -0,0 +1,8 @@ +module github.com/graphmetrics/logger-go/logrus + +go 1.15 + +require ( + github.com/graphmetrics/logger-go v0.2.0 + github.com/sirupsen/logrus v1.7.0 +) diff --git a/logrus/go.sum b/logrus/go.sum new file mode 100644 index 0000000..70017de --- /dev/null +++ b/logrus/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/graphmetrics/logger-go v0.2.0 h1:vzxwoe3wtvXHqh7urQ4MYtrOjlwDGDxEOsmEy9NH+o8= +github.com/graphmetrics/logger-go v0.2.0/go.mod h1:T98PXH1RF/nRghhhnKr8S7N96H5A7beuXXwzJaBl0dw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=