-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"errors"
"github.com/elgopher/yala/adapter/logrusadapter"
"github.com/elgopher/yala/logger"
"github.com/sirupsen/logrus"
)
var ErrSome = errors.New("some error")
// This example shows how to use yala with logrus adapter
func main() {
ctx := context.Background()
// First create a logrus logger.
l := newLogrusLogger()
// Then create a logger.Adapter.
adapter := logrusadapter.Adapter{
Logger: l, // you can also pass *logrus.Entry
}
// Create yala logger
log := logger.WithAdapter(adapter)
log.Debug(ctx, "Hello logrus")
log.InfoFields(ctx, "Some info", logger.Fields{
"field_name": "field_value",
"other_name": "field_value",
})
log.WarnFields(ctx, "Deprecated configuration parameter. It will be removed.", logger.Fields{
"parameter": "some",
})
log.ErrorCause(ctx, "Some error", ErrSome)
}
func newLogrusLogger() *logrus.Logger {
l := logrus.New()
l.SetLevel(logrus.DebugLevel)
l.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
})
return l
}