Skip to content

Commit

Permalink
Fix InitLogger just no work
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyang666 committed Jun 6, 2024
1 parent 61ecaa8 commit 5384128
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion clients/config_client/config_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const (
executorErrDelay = 5 * time.Second
)

var onceInitLogger sync.Once

type ConfigClient struct {
ctx context.Context
cancel context.CancelFunc
Expand Down Expand Up @@ -153,7 +155,11 @@ func NewConfigClient(nc nacos_client.INacosClient) (*ConfigClient, error) {
}

func initLogger(clientConfig constant.ClientConfig) error {
return logger.InitLogger(logger.BuildLoggerConfig(clientConfig))
var err error
onceInitLogger.Do(func() {
err = logger.InitLogger(logger.BuildLoggerConfig(clientConfig))
})
return err
}

func (client *ConfigClient) GetConfig(param vo.ConfigParam) (content string, err error) {
Expand Down
9 changes: 8 additions & 1 deletion clients/naming_client/naming_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math"
"math/rand"
"strings"
"sync"
"time"

"github.com/pkg/errors"
Expand All @@ -35,6 +36,8 @@ import (
"github.com/nacos-group/nacos-sdk-go/v2/vo"
)

var onceInitLogger sync.Once

// NamingClient ...
type NamingClient struct {
nacos_client.INacosClient
Expand Down Expand Up @@ -88,7 +91,11 @@ func NewNamingClient(nc nacos_client.INacosClient) (*NamingClient, error) {
}

func initLogger(clientConfig constant.ClientConfig) error {
return logger.InitLogger(logger.BuildLoggerConfig(clientConfig))
var err error
onceInitLogger.Do(func() {
err = logger.InitLogger(logger.BuildLoggerConfig(clientConfig))
})
return err
}

// RegisterInstance ...
Expand Down
3 changes: 0 additions & 3 deletions common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ func BuildLoggerConfig(clientConfig constant.ClientConfig) Config {
func InitLogger(config Config) (err error) {
logLock.Lock()
defer logLock.Unlock()
if logger != nil {
return
}
logger, err = InitNacosLogger(config)
return
}
Expand Down

0 comments on commit 5384128

Please sign in to comment.