MCPcopy
hub / github.com/go-kit/kit / Example_contextual

Function Example_contextual

log/example_test.go:32–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30}
31
32func Example_contextual() {
33 logger := log.NewLogfmtLogger(os.Stdout)
34
35 type Task struct {
36 ID int
37 Cmd string
38 }
39
40 taskHelper := func(cmd string, logger log.Logger) {
41 // execute(cmd)
42 logger.Log("cmd", cmd, "dur", 42*time.Millisecond)
43 }
44
45 RunTask := func(task Task, logger log.Logger) {
46 logger = log.With(logger, "taskID", task.ID)
47 logger.Log("event", "starting task")
48
49 taskHelper(task.Cmd, logger)
50
51 logger.Log("event", "task complete")
52 }
53
54 RunTask(Task{ID: 1, Cmd: "echo Hello, world!"}, logger)
55
56 // Output:
57 // taskID=1 event="starting task"
58 // taskID=1 cmd="echo Hello, world!" dur=42ms
59 // taskID=1 event="task complete"
60}
61
62func Example_valuer() {
63 logger := log.NewLogfmtLogger(os.Stdout)

Callers

nothing calls this directly

Calls 3

NewLogfmtLoggerFunction · 0.92
WithFunction · 0.92
LogMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…