handler_go14.go 469 B

123456789101112131415161718192021222324
  1. // +build go1.4
  2. package log
  3. import "sync/atomic"
  4. // swapHandler wraps another handler that may be swapped out
  5. // dynamically at runtime in a thread-safe fashion.
  6. type swapHandler struct {
  7. handler atomic.Value
  8. }
  9. func (h *swapHandler) Log(r *Record) error {
  10. return (*h.handler.Load().(*Handler)).Log(r)
  11. }
  12. func (h *swapHandler) Swap(newHandler Handler) {
  13. h.handler.Store(&newHandler)
  14. }
  15. func (h *swapHandler) Get() Handler {
  16. return *h.handler.Load().(*Handler)
  17. }