Skip to content

Commit 3aa633e

Browse files
committed
[LOGRUS] Initial version of logger
1 parent cacb5e3 commit 3aa633e

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

logrus/adapter.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package logrusadapter
2+
3+
import (
4+
"github.com/graphmetrics/logger-go"
5+
"github.com/graphmetrics/logger-go/options"
6+
"github.com/sirupsen/logrus"
7+
)
8+
9+
type logrusAdapter struct {
10+
parent *logrus.Logger
11+
}
12+
13+
func New(parent *logrus.Logger) logger.Logger {
14+
return &logrusAdapter{parent: parent}
15+
}
16+
17+
func (z *logrusAdapter) Debug(msg string, metadata map[string]interface{}) {
18+
entry := z.parent.WithFields(metadata)
19+
entry.Debug(msg)
20+
}
21+
22+
func (z *logrusAdapter) Info(msg string, metadata map[string]interface{}) {
23+
entry := z.parent.WithFields(metadata)
24+
entry.Info(msg)
25+
}
26+
27+
func (z *logrusAdapter) Warn(msg string, metadata map[string]interface{}) {
28+
entry := z.parent.WithFields(metadata)
29+
entry.Warn(msg)
30+
}
31+
32+
func (z *logrusAdapter) Error(msg string, metadata map[string]interface{}) {
33+
entry := z.parent.WithFields(metadata)
34+
entry.Error(msg)
35+
}
36+
37+
func (z *logrusAdapter) WithOptions(opts ...options.LoggerOption) logger.Logger {
38+
adapter := z
39+
for _, o := range opts {
40+
switch o.Parameter() {
41+
case "CallerSkipOffset":
42+
// Waiting on https://github.com/sirupsen/logrus/pull/1215 otherwise the caller is overriden anyway
43+
break
44+
case "Named":
45+
// Loggers don't have names
46+
break
47+
default:
48+
break
49+
}
50+
}
51+
return adapter
52+
}

logrus/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/graphmetrics/logger-go/logrus
2+
3+
go 1.15
4+
5+
require (
6+
github.com/graphmetrics/logger-go v0.2.0
7+
github.com/sirupsen/logrus v1.7.0
8+
)

logrus/go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/graphmetrics/logger-go v0.2.0 h1:vzxwoe3wtvXHqh7urQ4MYtrOjlwDGDxEOsmEy9NH+o8=
4+
github.com/graphmetrics/logger-go v0.2.0/go.mod h1:T98PXH1RF/nRghhhnKr8S7N96H5A7beuXXwzJaBl0dw=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
8+
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
9+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
10+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
11+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
12+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

0 commit comments

Comments
 (0)