Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InitLogger just no work #759

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading