it also check if context is canceld and if its so, it will not trying to send to it work function error. BREAKING CHANGE: it also takes now logr.Logger and stores it in the Dispatcher
37 lines
914 B
Markdown
37 lines
914 B
Markdown
# buflogr
|
|
|
|
[](https://pkg.go.dev/github.com/tonglil/buflogr)
|
|
<!--  -->
|
|
[](https://goreportcard.com/report/github.com/tonglil/buflogr)
|
|
|
|
A [logr](https://github.com/go-logr/logr) LogSink implementation using [bytes.Buffer](https://pkg.go.dev/bytes).
|
|
|
|
## Usage
|
|
|
|
```go
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/go-logr/logr"
|
|
"github.com/tonglil/buflogr"
|
|
)
|
|
|
|
func main() {
|
|
var buf bytes.Buffer
|
|
var log logr.Logger = buflogr.NewWithBuffer(&buf)
|
|
|
|
log = log.WithName("my app")
|
|
log := log.WithValues("format", "none")
|
|
|
|
log.Info("Logr in action!", "the answer", 42)
|
|
|
|
fmt.Print(buf.String())
|
|
}
|
|
```
|
|
|
|
## Implementation Details
|
|
|
|
This is a simple log adapter to log messages into a buffer.
|
|
Useful for testing.
|