You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by xu...@apache.org on 2026/05/27 11:16:02 UTC
(dubbo-go) branch develop updated: fix(logger): sync dubbo-go logger facade during logger initialization (#3345)
This is an automated email from the ASF dual-hosted git repository.
Alanxtl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new 80479284c fix(logger): sync dubbo-go logger facade during logger initialization (#3345)
80479284c is described below
commit 80479284c4326950bd91701ec5da4383732ea58c
Author: Nene7ko_ <14...@users.noreply.github.com>
AuthorDate: Wed May 27 19:15:56 2026 +0800
fix(logger): sync dubbo-go logger facade during logger initialization (#3345)
* fix(logger): sync dubbo-go logger facade in LoggerConfig.Init()
* fix(logger): sync dubbo-go logger facade in config_loader init()
* fix(logger): sync dubbo-go logger facade in initGlobalLogger()
* test(logger): verify dubbo-go facade is synced after logger initialization
* style(logger): fix import formatting
---
config/config_loader.go | 6 ++++--
config/logger_config.go | 8 +++++---
config/logger_config_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++
instance_options_init.go | 34 +++++++++++++++++---------------
4 files changed, 73 insertions(+), 21 deletions(-)
diff --git a/config/config_loader.go b/config/config_loader.go
index b7c859e15..c232cc894 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -23,13 +23,14 @@ import (
)
import (
- "github.com/dubbogo/gost/log/logger"
+ gostLogger "github.com/dubbogo/gost/log/logger"
"github.com/knadh/koanf"
)
import (
"dubbo.apache.org/dubbo-go/v3/common"
+ dubboLogger "dubbo.apache.org/dubbo-go/v3/logger"
_ "dubbo.apache.org/dubbo-go/v3/logger/core/logrus"
"dubbo.apache.org/dubbo-go/v3/logger/core/zap"
)
@@ -48,7 +49,8 @@ func setRootConfigInternal(rc *RootConfig) {
func init() {
log := zap.NewDefault()
- logger.SetLogger(log)
+ dubboLogger.SetLogger(log)
+ gostLogger.SetLogger(log)
}
func Load(opts ...LoaderConfOption) error {
diff --git a/config/logger_config.go b/config/logger_config.go
index 0696310d3..3db94807b 100644
--- a/config/logger_config.go
+++ b/config/logger_config.go
@@ -27,13 +27,14 @@ import (
"github.com/creasty/defaults"
- "github.com/dubbogo/gost/log/logger"
+ gostLogger "github.com/dubbogo/gost/log/logger"
)
import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
+ dubboLogger "dubbo.apache.org/dubbo-go/v3/logger"
)
type LoggerConfig struct {
@@ -88,7 +89,7 @@ func (l *LoggerConfig) Prefix() string {
func (l *LoggerConfig) Init() error {
var (
- log logger.Logger
+ log gostLogger.Logger
err error
)
if err = l.check(); err != nil {
@@ -99,7 +100,8 @@ func (l *LoggerConfig) Init() error {
return err
}
// set log
- logger.SetLogger(log)
+ gostLogger.SetLogger(log)
+ dubboLogger.SetLogger(log)
getty.SetLogger(log)
return nil
}
diff --git a/config/logger_config_test.go b/config/logger_config_test.go
index 4c6ca8481..a8c31ee6d 100644
--- a/config/logger_config_test.go
+++ b/config/logger_config_test.go
@@ -28,6 +28,10 @@ import (
"github.com/stretchr/testify/require"
)
+import (
+ dubboLogger "dubbo.apache.org/dubbo-go/v3/logger"
+)
+
func TestLoggerInit(t *testing.T) {
t.Run("empty use default", func(t *testing.T) {
err := Load(WithPath("./testdata/config/logger/empty_log.yaml"))
@@ -128,3 +132,45 @@ func TestLoggerConfigBuilder_TraceIntegration(t *testing.T) {
assert.Nil(t, config.TraceIntegration)
})
}
+
+func TestLoggerConfigInit_SyncsDubboFacade_Zap(t *testing.T) {
+ config := NewLoggerConfigBuilder().
+ SetDriver("zap").
+ SetLevel("info").
+ Build()
+
+ require.NoError(t, config.Init())
+ assert.NotNil(t, dubboLogger.GetLogger(), "dubbo-go logger facade should not be nil after LoggerConfig.Init()")
+}
+
+func TestLoggerConfigInit_SyncsDubboFacade_Logrus(t *testing.T) {
+ config := NewLoggerConfigBuilder().
+ SetDriver("logrus").
+ SetLevel("info").
+ Build()
+
+ require.NoError(t, config.Init())
+ assert.NotNil(t, dubboLogger.GetLogger(), "dubbo-go logger facade should not be nil after LoggerConfig.Init() with logrus driver")
+}
+
+func TestLoggerConfigInit_SetLoggerLevel_WorksAfterInit(t *testing.T) {
+ config := NewLoggerConfigBuilder().
+ SetDriver("zap").
+ SetLevel("info").
+ Build()
+
+ require.NoError(t, config.Init())
+ assert.True(t, dubboLogger.SetLoggerLevel("debug"), "SetLoggerLevel should return true after LoggerConfig.Init() with zap driver")
+}
+
+func TestLoggerConfigInit_TraceIntegration_FacadeNotNil(t *testing.T) {
+ config := NewLoggerConfigBuilder().
+ SetDriver("zap").
+ SetLevel("info").
+ SetTraceIntegrationEnabled(true).
+ Build()
+
+ require.NoError(t, config.Init())
+ assert.NotNil(t, dubboLogger.GetLogger(), "dubbo-go logger facade should not be nil after Init() with trace-integration enabled")
+ assert.True(t, dubboLogger.SetLoggerLevel("debug"), "SetLoggerLevel should work through ZapCtxLogger wrapper with trace-integration enabled")
+}
diff --git a/instance_options_init.go b/instance_options_init.go
index 58ae487f6..c1245a6c5 100644
--- a/instance_options_init.go
+++ b/instance_options_init.go
@@ -29,7 +29,7 @@ import (
"github.com/creasty/defaults"
- "github.com/dubbogo/gost/log/logger"
+ gostLogger "github.com/dubbogo/gost/log/logger"
"github.com/knadh/koanf"
@@ -45,6 +45,7 @@ import (
aslimiter "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
"dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/internal"
+ dubboLogger "dubbo.apache.org/dubbo-go/v3/logger"
"dubbo.apache.org/dubbo-go/v3/metrics"
metricsConfigCenter "dubbo.apache.org/dubbo-go/v3/metrics/config_center"
"dubbo.apache.org/dubbo-go/v3/otel/trace"
@@ -331,13 +332,13 @@ func (rc *InstanceOptions) initGlobalOtel(activateRuntime bool) error {
otel.SetTextMapPropagator(exporter.GetPropagator())
if c.Exporter == "stdout" {
- logger.Infof("enable %s trace provider with propagator: %s", c.Exporter, c.Propagator)
+ gostLogger.Infof("enable %s trace provider with propagator: %s", c.Exporter, c.Propagator)
} else {
- logger.Infof("enable %s trace provider with endpoint: %s, propagator: %s", c.Exporter, c.Endpoint, c.Propagator)
+ gostLogger.Infof("enable %s trace provider with endpoint: %s, propagator: %s", c.Exporter, c.Endpoint, c.Propagator)
}
- logger.Infof("sample mode: %s", c.SampleMode)
+ gostLogger.Infof("sample mode: %s", c.SampleMode)
if c.SampleMode == "ratio" {
- logger.Infof("sample ratio: %.2f", c.SampleRatio)
+ gostLogger.Infof("sample ratio: %.2f", c.SampleRatio)
}
}
return nil
@@ -396,8 +397,8 @@ func (rc *InstanceOptions) initGlobalProvider(activateRuntime bool) error {
return fmt.Errorf("the adaptive service is disabled, adaptive service verbose should be disabled either")
}
if activateRuntime {
- logger.Infof("adaptive service verbose is enabled.")
- logger.Debugf("debug-level info could be shown.")
+ gostLogger.Infof("adaptive service verbose is enabled.")
+ gostLogger.Debugf("debug-level info could be shown.")
aslimiter.Verbose = true
}
}
@@ -559,7 +560,8 @@ func (rc *InstanceOptions) initGlobalLogger() error {
if err != nil {
return err
}
- logger.SetLogger(log)
+ gostLogger.SetLogger(log)
+ dubboLogger.SetLogger(log)
getty.SetLogger(log)
return nil
}
@@ -616,18 +618,18 @@ func (rc *InstanceOptions) startGlobalConfigCenter() (bool, error) {
cc := rc.ConfigCenter
dynamicConfig, err := getGlobalDynamicConfiguration(cc)
if err != nil {
- logger.Errorf("[Config Center] Start dynamic configuration center error, error message is %v", err)
+ gostLogger.Errorf("[Config Center] Start dynamic configuration center error, error message is %v", err)
return false, err
}
strConf, err := dynamicConfig.GetProperties(cc.DataId, config_center.WithGroup(cc.Group))
if err != nil {
- logger.Warnf("[Config Center] Dynamic config center has started, but config may not be initialized, because: %s", err)
+ gostLogger.Warnf("[Config Center] Dynamic config center has started, but config may not be initialized, because: %s", err)
return false, nil
}
defer metrics.Publish(metricsConfigCenter.NewIncMetricEvent(cc.DataId, cc.Group, remoting.EventTypeAdd, cc.Protocol))
if len(strConf) == 0 {
- logger.Warnf("[Config Center] Dynamic config center has started, but got empty config with config-center configuration %+v\n"+
+ gostLogger.Warnf("[Config Center] Dynamic config center has started, but got empty config with config-center configuration %+v\n"+
"Please check if your config-center config is correct.", cc)
return false, nil
}
@@ -687,20 +689,20 @@ func globalConfigCenterURLMap(cc *global.CenterConfig) url.Values {
}
func (rc *InstanceOptions) Process(event *config_center.ConfigChangeEvent) {
- logger.Infof("CenterConfig process event:\n%+v", event)
+ gostLogger.Infof("CenterConfig process event:\n%+v", event)
if event == nil {
return
}
value, ok := event.Value.(string)
if !ok {
- logger.Errorf("CenterConfig process event value is not string")
+ gostLogger.Errorf("CenterConfig process event value is not string")
return
}
conf := NewLoaderConf(WithBytes([]byte(value)))
koan := GetConfigResolver(conf)
update := &InstanceOptions{}
if err := koan.UnmarshalWithConf(rc.Prefix(), update, koanf.UnmarshalConf{Tag: "yaml"}); err != nil {
- logger.Errorf("CenterConfig process unmarshalConf failed, got error %#v", err)
+ gostLogger.Errorf("CenterConfig process unmarshalConf failed, got error %#v", err)
return
}
@@ -710,12 +712,12 @@ func (rc *InstanceOptions) Process(event *config_center.ConfigChangeEvent) {
}
if registryConfig := rc.Registries[registryID]; registryConfig != nil && updateRegistry.Timeout != registryConfig.Timeout {
registryConfig.Timeout = updateRegistry.Timeout
- logger.Infof("RegistryConfigs Timeout was dynamically updated, new value:%v", registryConfig.Timeout)
+ gostLogger.Infof("RegistryConfigs Timeout was dynamically updated, new value:%v", registryConfig.Timeout)
}
}
if rc.Consumer != nil && update.Consumer != nil && update.Consumer.RequestTimeout != rc.Consumer.RequestTimeout {
rc.Consumer.RequestTimeout = update.Consumer.RequestTimeout
- logger.Infof("ConsumerConfig's RequestTimeout was dynamically updated, new value:%v", rc.Consumer.RequestTimeout)
+ gostLogger.Infof("ConsumerConfig's RequestTimeout was dynamically updated, new value:%v", rc.Consumer.RequestTimeout)
}
setCompatRootConfig(compatRootConfig(rc))