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
|
package main
import (
"errors"
"os"
"time"
"github.com/apex/log"
"github.com/apex/log/handlers/json"
"github.com/apex/log/handlers/multi"
"github.com/apex/log/handlers/text"
)
func main() {
log.SetHandler(multi.New(
text.New(os.Stderr),
json.New(os.Stderr),
))
ctx := log.WithFields(log.Fields{
"file": "something.png",
"type": "image/png",
"user": "tobi",
})
for range time.Tick(time.Millisecond * 200) {
ctx.Info("upload")
ctx.Info("upload complete")
ctx.Warn("upload retry")
ctx.WithError(errors.New("unauthorized")).Error("upload failed")
}
}
|