github.com/palisadeinc/bor@v0.0.0-20230615125219-ab7196213d15/log/handler_go119.go (about)

     1  //+go:build go1.19
     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.Pointer[Handler]
    11  }
    12  
    13  func (h *swapHandler) Log(r *Record) error {
    14  	return (*h.handler.Load()).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()
    23  }
    24  
    25  func (h *swapHandler) Level() Lvl {
    26  	return (*h.handler.Load()).Level()
    27  }