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 (
"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
}

Loading…
Cancel
Save