Skip to content

Instantly share code, notes, and snippets.

@tj
Created January 14, 2016 14:35
Show Gist options
  • Save tj/5c7593e8153100d21092 to your computer and use it in GitHub Desktop.
Save tj/5c7593e8153100d21092 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"time"
"github.com/apex/log"
"github.com/apex/log/handlers/text"
)
func work(ctx log.Interface) (err error) {
path := "Readme.md"
defer ctx.WithField("path", path).Trace("opening").Stop(&err)
_, err = os.Open(path)
return
}
func main() {
log.SetHandler(text.New(os.Stderr))
ctx := log.WithFields(log.Fields{
"app": "myapp",
"env": "prod",
})
for range time.Tick(time.Second) {
_ = work(ctx)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment