mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
a41e372b39
Former-commit-id: fa0dc873367b92a06b10fd989e3fec960c03065a [formerly e98efffa565ea6aa3eadeb19c2f9a66a56eb5ddd] Former-commit-id: ce6e4f01d12015e67a51aa7d928a6ab8e8eedeee
24 lines
469 B
Go
24 lines
469 B
Go
// +build go1.4
|
|
|
|
package log
|
|
|
|
import "sync/atomic"
|
|
|
|
// swapHandler wraps another handler that may be swapped out
|
|
// dynamically at runtime in a thread-safe fashion.
|
|
type swapHandler struct {
|
|
handler atomic.Value
|
|
}
|
|
|
|
func (h *swapHandler) Log(r *Record) error {
|
|
return (*h.handler.Load().(*Handler)).Log(r)
|
|
}
|
|
|
|
func (h *swapHandler) Swap(newHandler Handler) {
|
|
h.handler.Store(&newHandler)
|
|
}
|
|
|
|
func (h *swapHandler) Get() Handler {
|
|
return *h.handler.Load().(*Handler)
|
|
}
|