-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 1.05 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
package main
import (
"context"
"errors"
"github.com/elgopher/yala/adapter/zapadapter"
"github.com/elgopher/yala/logger"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var ErrSome = errors.New("ErrSome")
// This example shows how to use yala with zap adapter
func main() {
ctx := context.Background()
zapLogger := newZapLogger()
adapter := zapadapter.Adapter{Logger: zapLogger} // create logger.Adapter for zap
log := logger.WithAdapter(adapter) // Create yala logger
log.Debug(ctx, "Hello zap")
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 newZapLogger() *zap.Logger {
zapCfg := zap.NewDevelopmentConfig()
zapCfg.DisableStacktrace = true
zapCfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
zapLogger, err := zapCfg.Build()
if err != nil {
panic(err)
}
return zapLogger
}