1 package log 2 3 import ( 4 "io" 5 6 "github.com/go-kit/log" 7 ) 8 9 // SwapLogger wraps another logger that may be safely replaced while other 10 // goroutines use the SwapLogger concurrently. The zero value for a SwapLogger 11 // will discard all log events without error. 12 // 13 // SwapLogger serves well as a package global logger that can be changed by 14 // importers. 15 type SwapLogger = log.SwapLogger 16 17 // NewSyncWriter returns a new writer that is safe for concurrent use by 18 // multiple goroutines. Writes to the returned writer are passed on to w. If 19 // another write is already in progress, the calling goroutine blocks until 20 // the writer is available. 21 // 22 // If w implements the following interface, so does the returned writer. 23 // 24 // interface { 25 // Fd() uintptr 26 // } 27 func NewSyncWriter(w io.Writer) io.Writer { 28 return log.NewSyncWriter(w) 29 } 30 31 // NewSyncLogger returns a logger that synchronizes concurrent use of the 32 // wrapped logger. When multiple goroutines use the SyncLogger concurrently 33 // only one goroutine will be allowed to log to the wrapped logger at a time. 34 // The other goroutines will block until the logger is available. 35 func NewSyncLogger(logger Logger) Logger { 36 return log.NewSyncLogger(logger) 37 } 38