package diode
import "github.com/rs/zerolog/diode"
Package diode provides a thread-safe, lock-free, non-blocking io.Writer wrapper.
Index ¶
Examples ¶
Types ¶
type Alerter ¶
type Alerter func(missed int)
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a io.Writer wrapper that uses a diode to make Write lock-free, non-blocking and thread safe.
func NewWriter ¶
NewWriter creates a writer wrapping w with a many-to-one diode in order to never block log producers and drop events if the writer can't keep up with the flow of data.
Use a diode.Writer when
wr := diode.NewWriter(w, 1000, 0, func(missed int) { log.Printf("Dropped %d messages", missed) }) log := zerolog.New(wr)
If pollInterval is greater than 0, a poller is used otherwise a waiter is used.
See code.cloudfoundry.org/go-diodes for more info on diode.
Code:play
Output:Example¶
package main
import (
"fmt"
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/diode"
)
func main() {
w := diode.NewWriter(os.Stdout, 1000, 0, func(missed int) {
fmt.Printf("Dropped %d messages\n", missed)
})
log := zerolog.New(w)
log.Print("test")
w.Close()
}
{"level":"debug","message":"test"}
func (Writer) Close ¶
Close releases the diode poller and call Close on the wrapped writer if io.Closer is implemented.
func (Writer) Write ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
diode/internal |
- Version
- v1.33.0 (latest)
- Published
- May 4, 2024
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 36 minutes ago –
Tools for package owners.