mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 15:46:43 +00:00
* use atomic pointer * golang version * golang version * go1.19 * linters * Bump golangci-lint * linters * linters * linters after merge * generic logger * generic logger * logger * logger * linters * bump toml * linters1 * linters * linters * linter * linter * linters * linters * linters
27 lines
536 B
Go
27 lines
536 B
Go
//+go:build go1.19
|
|
|
|
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.Pointer[Handler]
|
|
}
|
|
|
|
func (h *swapHandler) Log(r *Record) error {
|
|
return (*h.handler.Load()).Log(r)
|
|
}
|
|
|
|
func (h *swapHandler) Swap(newHandler Handler) {
|
|
h.handler.Store(&newHandler)
|
|
}
|
|
|
|
func (h *swapHandler) Get() Handler {
|
|
return *h.handler.Load()
|
|
}
|
|
|
|
func (h *swapHandler) Level() Lvl {
|
|
return (*h.handler.Load()).Level()
|
|
}
|