-
-
Save tj/5c7593e8153100d21092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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