github.com/turingchain2020/turingchain@v1.1.21/common/log/log15/handler_go14.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build go1.4 6 7 package log15 8 9 import "sync/atomic" 10 11 // swapHandler wraps another handler that may be swapped out 12 // dynamically at runtime in a thread-safe fashion. 13 type swapHandler struct { 14 handler atomic.Value 15 } 16 17 func (h *swapHandler) Log(r *Record) error { 18 return (*h.handler.Load().(*Handler)).Log(r) 19 } 20 21 func (h *swapHandler) MaxLevel() int { 22 return (*h.handler.Load().(*Handler)).MaxLevel() 23 } 24 25 func (h *swapHandler) SetMaxLevel(maxLevel int) { 26 (*h.handler.Load().(*Handler)).SetMaxLevel(maxLevel) 27 } 28 29 func (h *swapHandler) Swap(newHandler Handler) { 30 h.handler.Store(&newHandler) 31 } 32 33 func (h *swapHandler) Get() Handler { 34 return *h.handler.Load().(*Handler) 35 }