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

在elastic 封装里面,会出现一个问题, 使用logger得错误 #2

Open
supermigo opened this issue Oct 11, 2022 · 0 comments

Comments

@supermigo
Copy link

当你未给utils 设置log得时候, 接下去得log 输出 会调用到err.error错误:
client, err := elastic.NewClient(
elastic.SetURL(host), elastic.SetSniff(false),
elastic.SetBasicAuth(user, password),
//elastic.SetErrorLog(logger), //关闭log 提示:

)

那么在是这种条件判断和logger得输出得 会出错

if err != nil {
logger.Error(err, logger.String(" some error occurred when check exists, index", index))
return false
}
if exists {
logger.Error(errors.New(""), logger.String(" index:{%s} is already exists", index)) //2
return true
}
在上面代码得2地方 其实err 为nil , 但是在logger 。error时候会强制用到err.error输出。
所以两个地方 || 得修改 要么在logger底层判断err 为nil 或者修改像我强制传递带指针得, 建议前者

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant