github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/log/handler_go14.go (about) 1 // +build go1.4 2 3 package log 4 5 import "sync/atomic" 6 7 // swapHandler wraps another handler that may be swapped out 8 // dynamically at runtime in a thread-safe fashion. 9 type swapHandler struct { 10 handler atomic.Value 11 } 12 13 func (h *swapHandler) Log(r *Record) error { 14 return (*h.handler.Load().(*Handler)).Log(r) 15 } 16 17 func (h *swapHandler) Swap(newHandler Handler) { 18 h.handler.Store(&newHandler) 19 } 20 21 func (h *swapHandler) Get() Handler { 22 return *h.handler.Load().(*Handler) 23 }