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 37 38 39 40 41 42 43 44 45 46 47 48
|
package main
import (
"errors"
"time"
"github.com/apex/log"
"github.com/apex/log/handlers/cli"
)
func main() {
log.SetHandler(cli.Default)
log.SetLevel(log.DebugLevel)
ctx := log.WithFields(log.Fields{
"file": "something.png",
"type": "image/png",
"user": "tobi",
})
go func() {
for range time.Tick(time.Second) {
ctx.Debug("doing stuff")
}
}()
go func() {
for range time.Tick(100 * time.Millisecond) {
ctx.Info("uploading")
ctx.Info("upload complete")
}
}()
go func() {
for range time.Tick(time.Second) {
ctx.Warn("upload slow")
}
}()
go func() {
for range time.Tick(2 * time.Second) {
err := errors.New("boom")
ctx.WithError(err).Error("upload failed")
}
}()
select {}
}
|