Bluemage/go/pkg/log/writer.go

29 lines
497 B
Go

package log
import (
"io"
"sync"
)
type WriteLocker interface {
io.Writer
sync.Locker
}
type writeLock struct {
sync.Mutex
io.Writer
}
// Lock wraps a WriteSyncer in a mutex to make it safe for concurrent use. In
// particular, *os.Files must be locked before use.
//
// If w is already a WriteLocker, it will be returned as is.
func Lock(w io.Writer) WriteLocker {
if wl, ok := w.(WriteLocker); ok {
// no need to layer on another lock
return wl
}
return &writeLock{Writer: w}
}