...
Source file
src/cdr.dev/slog/example_marshaller_test.go
1 package slog_test
2
3 import (
4 "context"
5 "os"
6
7 "cdr.dev/slog"
8 "cdr.dev/slog/sloggers/sloghuman"
9 )
10
11 type myStruct struct {
12 foo int
13 bar int
14 }
15
16 func (s myStruct) MarshalJSON() ([]byte, error) {
17 return slog.M(
18 slog.F("foo", s.foo),
19 slog.F("bar", s.foo),
20 ).MarshalJSON()
21 }
22
23 func Example_marshaller() {
24 l := slog.Make(sloghuman.Sink(os.Stdout))
25
26 l.Info(context.Background(), "wow",
27 slog.F("myStruct", myStruct{
28 foo: 1,
29 bar: 2,
30 }),
31 )
32
33
34 }
35
View as plain text