-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
36 lines (27 loc) · 1.1 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
package main
import (
"os"
"time"
"github.com/grafov/kiwi"
)
func main() {
// Bind a new logger to a variable. You may create any number of loggers.
log := kiwi.New()
// For starting write log records to some writer output should be initialized.
out := kiwi.SinkTo(os.Stdout, kiwi.AsLogfmt()).Start()
// setup context of the logger
log.With("userID", 1000, "host", "local", "startedAt", time.Now())
// This record will be supplemented by startedAt value of time.Now().String()
log.Add("sample", 1).Log()
// This record also will be supplemented by the same value of the time.
// Because context value evalueted when it was added by log.With().
log.Add("sample", 2).Log()
// You can provide deferred evaluation of context or log values if you add them wrapped
// with func() interface{}, where interface should be one of scalar golang types.
log.With("currentTime", func() string { return time.Now().String() })
// These records will be output each its own currentTime value because currentTime will
// be evaluated on each Log() call.
log.Log("sample", 3)
log.Log("sample", 4)
out.Flush()
}