github.com/klaytn/klaytn@v1.12.1/log/handler_go13.go (about) 1 // Copyright 2018 The klaytn Authors 2 // 3 // This file is derived from log/handler_go13.go (2018/06/04). 4 // See LICENSE in the top directory for the original copyright and license. 5 //go:build !go1.4 6 // +build !go1.4 7 8 package log 9 10 import ( 11 "sync/atomic" 12 "unsafe" 13 ) 14 15 // swapHandler wraps another handler that may be swapped out 16 // dynamically at runtime in a thread-safe fashion. 17 type swapHandler struct { 18 handler unsafe.Pointer 19 } 20 21 func (h *swapHandler) Log(r *Record) error { 22 return h.Get().Log(r) 23 } 24 25 func (h *swapHandler) Get() Handler { 26 return *(*Handler)(atomic.LoadPointer(&h.handler)) 27 } 28 29 func (h *swapHandler) Swap(newHandler Handler) { 30 atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler)) 31 }