Source File
logfmt_logger.go
Belonging Package
github.com/go-kit/log
package logimport ()type logfmtEncoder struct {*logfmt.Encoderbuf bytes.Buffer}func ( *logfmtEncoder) () {.Encoder.Reset().buf.Reset()}var logfmtEncoderPool = sync.Pool{New: func() interface{} {var logfmtEncoder.Encoder = logfmt.NewEncoder(&.buf)return &},}type logfmtLogger struct {w io.Writer}// NewLogfmtLogger returns a logger that encodes keyvals to the Writer in// logfmt format. Each log event produces no more than one call to w.Write.// The passed Writer must be safe for concurrent use by multiple goroutines if// the returned Logger will be used concurrently.func ( io.Writer) Logger {return &logfmtLogger{}}func ( logfmtLogger) ( ...interface{}) error {:= logfmtEncoderPool.Get().(*logfmtEncoder).Reset()defer logfmtEncoderPool.Put()if := .EncodeKeyvals(...); != nil {return}// Add newline to the end of the bufferif := .EndRecord(); != nil {return}// The Logger interface requires implementations to be safe for concurrent// use by multiple goroutines. For this implementation that means making// only one call to l.w.Write() for each call to Log.if , := .w.Write(.buf.Bytes()); != nil {return}return nil}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |