mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
da20785685
Former-commit-id: 23f542f43b4b493e38f5aa4c29788ed93a63b43b [formerly 71b23a6a28eb045fcfeab6329de69f1e5455486b] Former-commit-id: d12b3a6decc876f010a71f98e11df7387c1aaf2a
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)
|
|
}
|