Skip to content

Commit

Permalink
[LOGRUS] Initial version of logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytten committed Feb 6, 2021
1 parent cacb5e3 commit 3aa633e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
52 changes: 52 additions & 0 deletions logrus/adapter.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions logrus/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
12 changes: 12 additions & 0 deletions logrus/go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit 3aa633e

Please sign in to comment.