2021-02-01 00:10:16 +01:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2021-09-27 17:01:40 +02:00
|
|
|
|
|
|
|
"github.com/go-kit/log"
|
2021-02-01 00:10:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// SwapLogger wraps another logger that may be safely replaced while other
|
|
|
|
// goroutines use the SwapLogger concurrently. The zero value for a SwapLogger
|
|
|
|
// will discard all log events without error.
|
|
|
|
//
|
|
|
|
// SwapLogger serves well as a package global logger that can be changed by
|
|
|
|
// importers.
|
2021-09-27 17:01:40 +02:00
|
|
|
type SwapLogger = log.SwapLogger
|
2021-02-01 00:10:16 +01:00
|
|
|
|
|
|
|
// NewSyncWriter returns a new writer that is safe for concurrent use by
|
|
|
|
// multiple goroutines. Writes to the returned writer are passed on to w. If
|
|
|
|
// another write is already in progress, the calling goroutine blocks until
|
|
|
|
// the writer is available.
|
|
|
|
//
|
|
|
|
// If w implements the following interface, so does the returned writer.
|
|
|
|
//
|
|
|
|
// interface {
|
|
|
|
// Fd() uintptr
|
|
|
|
// }
|
|
|
|
func NewSyncWriter(w io.Writer) io.Writer {
|
2021-09-27 17:01:40 +02:00
|
|
|
return log.NewSyncWriter(w)
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSyncLogger returns a logger that synchronizes concurrent use of the
|
|
|
|
// wrapped logger. When multiple goroutines use the SyncLogger concurrently
|
|
|
|
// only one goroutine will be allowed to log to the wrapped logger at a time.
|
|
|
|
// The other goroutines will block until the logger is available.
|
|
|
|
func NewSyncLogger(logger Logger) Logger {
|
2021-09-27 17:01:40 +02:00
|
|
|
return log.NewSyncLogger(logger)
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|