-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_test.go
More file actions
30 lines (21 loc) · 894 Bytes
/
example_test.go
File metadata and controls
30 lines (21 loc) · 894 Bytes
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
package logger_test
import (
"context"
"os"
"github.com/hamba/logger/v2"
"github.com/hamba/logger/v2/ctx"
)
func ExampleNew() {
log := logger.New(os.Stdout, logger.LogfmtFormat(), logger.Info).With(ctx.Str("env", "prod"))
log.Info("redis connection", ctx.Str("redis", "some redis name"), ctx.Int("timeout", 10))
}
func ExampleSyncWriter() {
log := logger.New(logger.NewSyncWriter(os.Stdout), logger.LogfmtFormat(), logger.Info).With(ctx.Str("env", "prod"))
log.Info("redis connection", ctx.Str("redis", "some redis name"), ctx.Int("timeout", 10))
}
func ExampleWithContext() {
log := logger.New(os.Stdout, logger.LogfmtFormat(), logger.Info).With(ctx.Str("svc", "api"))
reqCtx := logger.WithContext(context.Background(), log, ctx.Str("req_id", "abc-123"), ctx.Str("method", "GET"))
reqLog := log.FromContext(reqCtx)
reqLog.Info("request handled", ctx.Int("status", 200))
}