2
0

sync.go 1.2 KB

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