Skip to content

refactor(logger): standardize logger format across codebase#3344

Merged
Alanxtl merged 4 commits into
apache:developfrom
Qiao-yq:refactor/logger-format
May 28, 2026
Merged

refactor(logger): standardize logger format across codebase#3344
Alanxtl merged 4 commits into
apache:developfrom
Qiao-yq:refactor/logger-format

Conversation

@Qiao-yq
Copy link
Copy Markdown
Contributor

@Qiao-yq Qiao-yq commented May 27, 2026

Description

Fixes #3295

Summary

Standardize logger format across the dubbo-go codebase following a unified
convention. All logger calls are updated with consistent module prefixes,
unified key=value formatting, lowercase message bodies, and several
long-standing logger API misuses are fixed.

Changes

Prefix Convention

Every logger call now includes a [Module][SubModule] CamelCase prefix:

Module Prefix
graceful_shutdown [GracefulShutdown]
internal [Internal]
metadata [Metadata], [MetadataRPC]
metadata/report/etcd [MetadataReport][Etcd]
metadata/report/nacos [MetadataReport][Nacos]
metadata/report/zookeeper [MetadataReport][Zookeeper]
metrics [Metrics]
metrics/probe [Metrics][Probe]
metrics/prometheus [Metrics][Prometheus]
metrics/rpc [Metrics][RPC]
otel/trace [OTel][Trace]
protocol/base [Protocol]
protocol/dubbo [Dubbo], [Dubbo][Codec/Hessian2/Impl/Exporter/Invoker]
protocol/dubbo3 [Dubbo3]
protocol/grpc [GRPC], [GRPC][Client/Server/Exporter/Invoker]
protocol/jsonrpc [Jsonrpc], [Jsonrpc][Server/Exporter/Invoker]
protocol/rest [Rest], [Rest][Config/Exporter/Server]
protocol/triple [Triple], [Triple][Client/Server/Exporter/Invoker/CORS/Codec/Handler/Negotiation/Protocol/Health/OpenAPI]

Key Format Unification

  • error: %v / err: %v / error:{%v} / : %verr=%v
  • url: %surl=%s
  • revision: %srevision=%s
  • All keys use key=%v format separated by ,

Message Body

  • All message body first letters changed to lowercase (except proper nouns)
  • Removed decoration symbols (---)
  • Removed %+v format specifiers for non-Debug levels

Bug Fixes

  • logger.Error(err) where err is an error type → logger.Errorf("...err=%v", err)
    (dubbo_codec.go, dubbo_protocol.go, exporter.go ×2)
  • logger.Error("msg", extraArg) where extraArg was silently dropped →
    logger.Errorf("msg %s", extraArg) (rpc_status.go ×3, listener.go, server.go)
  • logger.Errorf(formatErr.Error()) with no format args →
    logger.Error("[Module] " + formatErr.Error()) (metadata_service.go)
  • logger.Infof/Debugf without format args → logger.Info/Debug
    (config.go ×2, report.go, triple.go ×3, etc.)
  • err.Error() + %serr + %v (nacos/report.go ×2, dubbo3_protocol.go)

Checklist

  • I confirm the target branch is develop
  • Code has passed local testing
  • I have added tests that prove my fix is effective or that my feature works

Qiao-yq added 3 commits May 27, 2026 10:55
- Add [GracefulShutdown] prefix to all logger calls
- Remove decoration symbols (---) from log messages
- Change key format from "error: %v" / "--- %v" to "err=%v"
- Lowercase first letter of all log message bodies
…trics, otel

- Add module prefixes: [Internal], [Metadata], [MetadataRPC], [MetadataReport][Etcd/Nacos/Zookeeper], [Metrics], [Metrics][Probe/Prometheus/RPC], [OTel][Trace]
- Unify key format: "error: %v" / ": %v" / "err: %s" → "err=%v", "url: %s" → "url=%s"
- Lowercase first letter of all log message bodies
- Fix bug: logger.Error with non-string or extra args → logger.Errorf (listener.go, server.go, exporter.go)
- Fix bug: logger.Errorf with no format args → logger.Error (metadata_service.go)
- Fix bug: logger.Infof/Debugf with no format args → logger.Info/Debug (config.go, report.go)
- Fix: err.Error() + %s → err + %v (nacos/report.go x2)
- Unify prefixes as [Protocol], [Dubbo], [Dubbo][Codec/Hessian2/Impl/Exporter/Invoker], [Dubbo3], [GRPC], [GRPC][Client/Server/Exporter/Invoker], [Jsonrpc], [Jsonrpc][Server/Exporter/Invoker], [ProtocolWrapper], [Rest], [Rest][Config/Exporter/Server], [Triple], [Triple][Client/Server/Exporter/Invoker/CORS/Codec/Handler/Negotiation/Protocol/Health/OpenAPI]
- Unify key format: "error: %v" / ": %v" / "error:{%v}" → "err=%v", "err: %v" → "err=%v"
- Lowercase first letter of all log message bodies
- Remove %+v format for non-Debug levels
- Fix bug: logger.Error with error type → logger.Errorf (dubbo_codec.go, dubbo_protocol.go)
- Fix bug: logger.Error/Info with extra args → logger.Errorf/Infof (rpc_status.go, jsonrpc/server.go)
- Fix bug: logger.Infof/Debugf without format args → logger.Info/Debug (multiple files)
- Fix bug: logger.Debug without format args → logger.Debugf (openapi/service.go)
- Fix: err.Error() + %s → err + %v (dubbo3_protocol.go)
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 27, 2026

Codecov Report

❌ Patch coverage is 32.92181% with 163 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.45%. Comparing base (60d1c2a) to head (b636ca1).
⚠️ Report is 807 commits behind head on develop.

Files with missing lines Patch % Lines
protocol/rest/server/rest_server.go 0.00% 14 Missing ⚠️
protocol/jsonrpc/server.go 26.66% 11 Missing ⚠️
protocol/dubbo3/dubbo3_protocol.go 0.00% 10 Missing ⚠️
graceful_shutdown/shutdown.go 66.66% 8 Missing ⚠️
protocol/dubbo3/dubbo3_invoker.go 0.00% 8 Missing ⚠️
protocol/dubbo/dubbo_codec.go 0.00% 7 Missing ⚠️
protocol/grpc/client.go 0.00% 7 Missing ⚠️
metadata/client.go 25.00% 6 Missing ⚠️
protocol/triple/server.go 33.33% 6 Missing ⚠️
metrics/prometheus/registry.go 37.50% 5 Missing ⚠️
... and 36 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3344      +/-   ##
===========================================
+ Coverage    46.76%   52.45%   +5.69%     
===========================================
  Files          295      492     +197     
  Lines        17172    37790   +20618     
===========================================
+ Hits          8031    19824   +11793     
- Misses        8287    16365    +8078     
- Partials       854     1601     +747     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread metadata/report/etcd/report.go Outdated
Comment thread metadata/client.go Outdated
Comment thread protocol/dubbo/impl/codec.go Outdated
Comment thread protocol/triple/triple_protocol/protocol_triple.go Outdated
Comment thread protocol/triple/triple_protocol/protocol_triple.go Outdated
@Alanxtl Alanxtl added 🧹 Updates 3.3.2 version 3.3.2 labels May 27, 2026
@Alanxtl Alanxtl linked an issue May 27, 2026 that may be closed by this pull request
@sonarqubecloud
Copy link
Copy Markdown

@Alanxtl Alanxtl merged commit 2540f01 into apache:develop May 28, 2026
8 checks passed
Alanxtl pushed a commit that referenced this pull request May 31, 2026
* fix(config): remove legacy protocol timeout fallback (#3326)

* fix(config): remove legacy protocol timeout fallback

* fix(config): avoid default timeout allocation

* fix(config): preserve consumer timeout in reference config

* test(config): satisfy testifylint in reference timeout test

* fix(config): make protocol timeout default explicit

* fix(config): centralize consumer timeout default

* fix(config): keep consumer timeout default in global

* Fix(config center)apollo context path error (#3331)

* feat(test):Add TestGetAddressWithProtocolPrefixKeepsContext and find the error when user bring context path

* fix(apollo):Fix the test func(getAddressWithProtocolPrefix) fix(context_path):fix getAddressWithProtolPrefix didn't handle context path

* refator(config_center):cleanup-redundant-test

* fix(test):删除不应该存在的文件

* feat():恢复测试并添加多种case

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix:修复url.Path = /问题并添加边缘测试;修复原来的不符合gofmt格式以通过CI

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* 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

* refactor(logger): standardize logger format across codebase (#3344)

* refactor(logger): standardize logger format in graceful_shutdown

- Add [GracefulShutdown] prefix to all logger calls
- Remove decoration symbols (---) from log messages
- Change key format from "error: %v" / "--- %v" to "err=%v"
- Lowercase first letter of all log message bodies

* refactor(logger): standardize logger format in internal, metadata, metrics, otel

- Add module prefixes: [Internal], [Metadata], [MetadataRPC], [MetadataReport][Etcd/Nacos/Zookeeper], [Metrics], [Metrics][Probe/Prometheus/RPC], [OTel][Trace]
- Unify key format: "error: %v" / ": %v" / "err: %s" → "err=%v", "url: %s" → "url=%s"
- Lowercase first letter of all log message bodies
- Fix bug: logger.Error with non-string or extra args → logger.Errorf (listener.go, server.go, exporter.go)
- Fix bug: logger.Errorf with no format args → logger.Error (metadata_service.go)
- Fix bug: logger.Infof/Debugf with no format args → logger.Info/Debug (config.go, report.go)
- Fix: err.Error() + %s → err + %v (nacos/report.go x2)

* refactor(logger): standardize logger format in protocol directory

- Unify prefixes as [Protocol], [Dubbo], [Dubbo][Codec/Hessian2/Impl/Exporter/Invoker], [Dubbo3], [GRPC], [GRPC][Client/Server/Exporter/Invoker], [Jsonrpc], [Jsonrpc][Server/Exporter/Invoker], [ProtocolWrapper], [Rest], [Rest][Config/Exporter/Server], [Triple], [Triple][Client/Server/Exporter/Invoker/CORS/Codec/Handler/Negotiation/Protocol/Health/OpenAPI]
- Unify key format: "error: %v" / ": %v" / "error:{%v}" → "err=%v", "err: %v" → "err=%v"
- Lowercase first letter of all log message bodies
- Remove %+v format for non-Debug levels
- Fix bug: logger.Error with error type → logger.Errorf (dubbo_codec.go, dubbo_protocol.go)
- Fix bug: logger.Error/Info with extra args → logger.Errorf/Infof (rpc_status.go, jsonrpc/server.go)
- Fix bug: logger.Infof/Debugf without format args → logger.Info/Debug (multiple files)
- Fix bug: logger.Debug without format args → logger.Debugf (openapi/service.go)
- Fix: err.Error() + %s → err + %v (dubbo3_protocol.go)

* refactor(logger):standardize logger prefixes in metadata, metadata-report, Dubbo, and Triple protocol modules

* refactor(logger): unify log format in proxy and registry packages

- Add consistent [Proxy]/[Registry]/[Registry][<impl>] prefix to all log messages
- Adopt key=value parameter style (err=%v, url=%s) for structured logging
- Remove redundant descriptions and normalize punctuation across 30 files

* refactor(logger): unify log format in remoting, server and loader modules

- Add consistent [Loader]/[Server]/[Getty]/[Zookeeper]/[Etcdv3] prefixes
- Adopt key=value parameter style (err=%v, url=%s) for structured logging
- Remove trailing punctuation and redundant wording across 21 files

* feat(tools): add loggercheck linter for log format consistency

Introduce a static analysis tool that enforces the standardized logger
conventions across the codebase:

- Rule 1: logger.Info with format verbs → use logger.Infof
- Rule 2: logger.Infof without format verbs → use logger.Info
- Rule 3: logger.Infof(fmt.Sprintf(...)) → redundant, flatten to Infof
- Rule 4: trailing \n / ... / ! in log messages → remove

Integrated into make lint as the logger-check target.

* refactor(logger): final touch, unfiy logger format in other places

* fix(tools): remove unused variables in loggercheck to pass golangci-lint

* refactor: revert (feat(tools): add loggercheck) and simplify registry log prefixes

Remove loggercheck tool and its Makefile integration. Use [Registry] instead of [Registry][Protocol]/[Registry][Exposed] in core registry files; add [Registry][Mock] for mock registry

* fix(logger): correct format verbs, variable names, and function calls

* refactor(logger):modify prefix format

---------

Co-authored-by: CAICAII <3360776475@qq.com>
Co-authored-by: Yuxuan Lv <3656828039@qq.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Nene7ko_ <141395478+XnLemon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[提案] 统一 dubbo-go 中 logger 输出信息的格式

3 participants