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