add singleton for logging

pull/231/head
Minh Doan 6 years ago
parent 798b6d22bb
commit d0247f0bb7
  1. 11
      internal/utils/singleton.go

@ -5,6 +5,8 @@ package utils
import ( import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/harmony-one/harmony/log"
) )
// UniqueValidatorID defines the structure of unique validator ID // UniqueValidatorID defines the structure of unique validator ID
@ -13,7 +15,9 @@ type UniqueValidatorID struct {
} }
var instance *UniqueValidatorID var instance *UniqueValidatorID
var logInstance log.Logger
var once sync.Once var once sync.Once
var onceForLog sync.Once
// GetUniqueValidatorIDInstance returns a singleton instance // GetUniqueValidatorIDInstance returns a singleton instance
func GetUniqueValidatorIDInstance() *UniqueValidatorID { func GetUniqueValidatorIDInstance() *UniqueValidatorID {
@ -29,3 +33,10 @@ func GetUniqueValidatorIDInstance() *UniqueValidatorID {
func (s *UniqueValidatorID) GetUniqueID() uint32 { func (s *UniqueValidatorID) GetUniqueID() uint32 {
return atomic.AddUint32(&s.uniqueID, 1) return atomic.AddUint32(&s.uniqueID, 1)
} }
func GetLogInstance() log.Logger {
onceForLog.Do(func() {
logInstance = log.New()
})
return logInstance
}

Loading…
Cancel
Save