From d0247f0bb748aea0bc7a4e51b2ee814f5586fe47 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Tue, 8 Jan 2019 15:31:03 -0800 Subject: [PATCH] add singleton for logging --- internal/utils/singleton.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/utils/singleton.go b/internal/utils/singleton.go index fa2ffc9c8..55e44193e 100644 --- a/internal/utils/singleton.go +++ b/internal/utils/singleton.go @@ -5,6 +5,8 @@ package utils import ( "sync" "sync/atomic" + + "github.com/harmony-one/harmony/log" ) // UniqueValidatorID defines the structure of unique validator ID @@ -13,7 +15,9 @@ type UniqueValidatorID struct { } var instance *UniqueValidatorID +var logInstance log.Logger var once sync.Once +var onceForLog sync.Once // GetUniqueValidatorIDInstance returns a singleton instance func GetUniqueValidatorIDInstance() *UniqueValidatorID { @@ -29,3 +33,10 @@ func GetUniqueValidatorIDInstance() *UniqueValidatorID { func (s *UniqueValidatorID) GetUniqueID() uint32 { return atomic.AddUint32(&s.uniqueID, 1) } + +func GetLogInstance() log.Logger { + onceForLog.Do(func() { + logInstance = log.New() + }) + return logInstance +}