-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
os/gtime: issue title looger The log component cannot record the custom context key #3813
Comments
@lixianpei 不能自定义类型,否则ctx.Value无法读取到你的值 CC@JimDevil |
@lixianpei You cannot customize the type, otherwise ctx.Value cannot read your value CC@JimDevil |
yeah,you are right! |
@lixianpei can be used like this: const CtxCrontabSnKey gctx.StrKey = "crontabSn" The gf source code is as follows: // The key point here is this part, the default type expected is gctx.StrKey. So using gctx.StrKey is most appropriate
ctxValue = ctx.Value(gctx.StrKey(gconv.String(ctxKey))) So I don't think this is a bug, but it can definitely be modified in the document. CC @JimDevil |
配置: ` import ( type BatchSnType string const BatchSn BatchSnType = "batchSn" func main() { ` 日志内容:只有A记录了,B没有记录(似乎无法直接用别名) |
@lixianpei Yes, aliases cannot be used, the reason has been explained above, and the official documentation of gf has been updated. https://goframe.org/pages/viewpage.action?pageId=1114222 |
thanks~ |
Go version
go 1.22
GoFrame version
v2.7.2
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
type CtxCrontabSnKeyType string
const CtxCrontabSnKey CtxCrontabSnKeyType = "crontabSn"
#【异常】定义一个上下文,自定义上下文key,希望能够在log文件中同时打印这个字符串“ABC”
ctx = context.WithValue(c, CtxCrontabSnKey, "ABC")
#【正确】直接使用字符串则是正确的
ctx = context.WithValue(c, "crontabSn", "ABC")
What did you see happen?
在log文件中无法正常打印自定义的上下文key=crontabSn的值
What did you expect to see?
即使使用别名定义的key也能在log文件中正常打印自定义的上下文key=crontabSn的值
The text was updated successfully, but these errors were encountered: