Qiao-yq commented on issue #3295:
URL: https://github.com/apache/dubbo-go/issues/3295#issuecomment-4303978729
目前日志的规范按照issue上面提到的要求可以吗
1. 明确日志文案规范
约定统一的日志输出风格,例如:
- 使用简洁、可检索的动作型表达;
- 组件需要显式标识时,统一使用 `[component]` 前缀;
- 参数统一放在消息后半段,优先使用 `key=value`;
- 不使用 `...`、`!`、`\n`、`---` 这类装饰性写法;
- 固定字符串使用 `Info/Warn/Error`;
- 只有在确实需要格式化参数时才使用 `Infof/Warnf/Errorf`;
- 禁止 `logger.*f(fmt.Sprintf(...))`。
我先尝试修改了上述典型样例,这些修改是否可以
1. 使用装饰性分隔符 `---`
- `config/graceful_shutdown.go:113`
`logger.Info("Graceful shutdown --- Execute the custom callbacks.")`
- `config/graceful_shutdown.go:121`
`logger.Info("Graceful shutdown --- Destroy all registriesConfig. ")`
**修改后:**
`logger.Info("[Graceful shutdown] Execute the custom callbacks")`
`logger.Info("[Graceful shutdown] Destroy all registriesConfig")`
2. 使用省略号 `...`
- `loader.go:446`
`logger.Info("Stopping file watcher...")`
**修改后:**
`logger.Info("Stopping file watcher")`
3. 使用模块 tag 前缀
- `cluster/router/tag/router.go:125`
`logger.Infof("[tag router] Applied static tag router config: key=%s",
key)`
**修改后:**
`logger.Infof("[Router] Applied static tag router config: key=%s", key)`
或者参考`cluster/router/tag/router.go:101`,不使用`[component]` 前缀
`logger.Infof("Applied static tag router config: key=%s", key)`
4. 文案风格偏口语 / 不够规范
- `registry/polaris/registry.go:166`
`logger.Infof("update begin, service event: %v", serviceEvent.String())`
**修改后:**
`logger.Infof("update started, serviceEvent=%v", serviceEvent.String())`
5. `Infof/Errorf` 用于纯静态字符串
- `protocol/dubbo3/dubbo3_invoker.go:156`
`logger.Infof("DUBBO3 Server initialized the TLSConfig configuration")`
- `protocol/dubbo3/dubbo3_protocol.go:285`
`logger.Infof("DUBBO3 Server initialized the TLSConfig configuration")`
**修改后:**
`logger.Info("DUBBO3 Server initialized the TLSConfig configuration")`
`logger.Info("DUBBO3 Server initialized the TLSConfig configuration")`
6. `Error` 误用格式化占位符,可能导致输出不符合预期
- `config/metadata_config.go:80`
`logger.Error("MetadataService port parse error %v, MetadataService will
use random port", err)`
- `server/server.go:423`
`logger.Error("MetadataService port parse error %v, MetadataService will
use random port", err)`
- `filter/polaris/limit/limiter.go:146`
`logger.Error("[TpsLimiter][Polaris] ns:%s svc:%s get RateLimit Rule fail
: %+v", req.GetNamespace(), req.GetService(), err)`
- `protocol/jsonrpc/server.go:97`
`logger.Error("connection.SetDeadline(t:%v) = error:%v", t, err)`
- `remoting/getty/pool.go:140`
`logger.Error("tcpConn.SetNoDelay() = error:%v", err)`
**修改后:**
`logger.Errorf("MetadataService port parse err=%v, MetadataService will use
random port", err)`
`logger.Errorf("MetadataService port parse err=%v, MetadataService will use
random port", err)`
`logger.Errorf("[TpsLimiter] ns=%s svc=%s get RateLimit Rule fail,
error=%+v", req.GetNamespace(), req.GetService(), err)`
`logger.Errorf("Set deadline failed t=%v, error=%v", t, err)`
`logger.Errorf("[Getty pool] SetNoDelay failed error=%v", err)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]