Add example to README

This commit is contained in:
Elara 2022-06-30 13:41:55 -07:00
parent 0fbc5dd1d9
commit 1726280154
2 changed files with 34 additions and 1 deletions

View File

@ -32,3 +32,36 @@ BenchmarkPretty/all-8 285554 3726 ns/op
``` ```
To run the benchmarks yourself, simply clone this repo and run `go test -bench=.`. Keep in mind that they will be different, depending on what your computer's specs are. To run the benchmarks yourself, simply clone this repo and run `go test -bench=.`. Keep in mind that they will be different, depending on what your computer's specs are.
### Example
```go
package main
import (
"strconv"
"os"
"go.arsenm.dev/logger/log"
"go.arsenm.dev/logger"
)
func init() {
// Default logger is JSONLogger going to stderr
log.Logger = logger.NewPretty(os.Stdout)
}
func main() {
s := "hello"
i, err := strconv.Atoi(s)
if err != nil {
log.Error("Couldn't convert to integer").
Str("input", s).
Err(err).
Send()
}
log.Info("Converted to integer").
Int("output", i).
Send()
}
```

View File

@ -1,7 +1,7 @@
package log package log
import ( import (
"logger" "go.arsenm.dev/logger"
"os" "os"
) )