-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
36 lines (28 loc) · 788 Bytes
/
example_test.go
File metadata and controls
36 lines (28 loc) · 788 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
31
32
33
34
35
36
package logging
import (
"context"
"os"
)
func Example_logLevelFromEnv() {
os.Setenv("LOG_LEVEL", "DEBUG")
defer os.Unsetenv("LOG_LEVEL")
ctx := context.Background()
ctx = ContextWithLogFields(ctx, "req-1", "tenant-a", "worker-7", "context-manager")
SetDefaultLogger(New())
Info(ctx, "started")
Debug(ctx, "detail", "key", "value")
}
func Example_context() {
ctx := context.Background()
ctx = ContextWithLogFields(ctx, "req-123", "tenant-42", "main", "http-handler")
ctx = Context(ctx, "user_id", 42)
SetDefaultLogger(New())
Info(ctx, "request handled", "user_id", 42)
}
func Example_fromContext() {
ctx := context.Background()
ctx = Context(ctx, "trace_id", "abc")
data := FromContext(ctx)
// data is map[string]interface{} with "trace_id" -> "abc"
_ = data
}