kratos icon indicating copy to clipboard operation
kratos copied to clipboard

The depth of the log package helper caller needs to be controlled separately, which is too cumbersome

Open tianping526 opened this issue 3 years ago • 4 comments

What happened:

在log包helper.go中,其他方法(如Debug、Info)比Log方法调用层级多一层,也比log.go 中的Log方法多一层,导致每次使用Helper都需要单独控制Caller的Depth,非常繁琐。

What you expected to happen:

Helper的其他方法和Log方法具有相同的调用深度,配置一次Caller的Depth,在所有日志使用场景都使用适用,而不需要单独控制。其修改也很简单,示例如下:

// 旧代码
func (h *Helper) Debug(a ...interface{}) {
	h.Log(LevelDebug, h.msgKey, fmt.Sprint(a...))
}

// 修改后
func (h *Helper) Debug(a ...interface{}) {
	_ = h.logger.Log(LevelDebug, h.msgKey, fmt.Sprint(a...))
}

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Kratos version (use kratos -v): v2.1.0
  • Go version (use go version):
  • OS (e.g: cat /etc/os-release):
  • Others:

tianping526 avatar Oct 28 '21 02:10 tianping526

可以帮直接提个pr?

tonybase avatar Oct 28 '21 05:10 tonybase

同感,因为helper不如zap的函数方便,我现在为了与helper保持一样的深度,对zap的函数包了两层,麻烦。

letian0805 avatar Oct 29 '21 08:10 letian0805

可以帮直接提个pr?

已经提交了,快来瞅瞅

tianping526 avatar Oct 30 '21 06:10 tianping526

也遇到了这个问题,中间件 logging 和 recovery 的写日志层级不一样

windzhu0514 avatar Jul 31 '22 02:07 windzhu0514

Hi, @tianping526! I'm Dosu, and I'm here to help the kratos team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you raised an issue regarding the need to control the depth of the log package helper caller separately. You suggested that the other methods in the helper package should have the same call depth as the Log method to make it easier to control the caller's depth. There have been a few comments from other users, such as tonybase and letian0805, who share similar sentiments and have suggested possible solutions.

Before we proceed, we would like to confirm if this issue is still relevant to the latest version of the kratos repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.

Thank you for your contribution, and we appreciate your understanding as we work to manage the repository effectively. If you have any further questions or concerns, please don't hesitate to reach out.

dosubot[bot] avatar Nov 02 '23 16:11 dosubot[bot]