github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/log/handler_go13.go (about) 1 //go:build !go1.4 2 // +build !go1.4 3 4 package log 5 6 import ( 7 "sync/atomic" 8 "unsafe" 9 ) 10 11 type swapHandler struct { 12 handler unsafe.Pointer 13 } 14 15 func (h *swapHandler) Log(r *Record) error { 16 return h.Get().Log(r) 17 } 18 19 func (h *swapHandler) Get() Handler { 20 return *(*Handler)(atomic.LoadPointer(&h.handler)) 21 } 22 23 func (h *swapHandler) Swap(newHandler Handler) { 24 atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler)) 25 }