go-zero
go-zero copied to clipboard
Add hook in logx, to get runtime values.
Is your feature request related to a problem? Please describe. 类似于 logrus 提供 AddHook 接口, 我可以防火获取运行时的值, 比如, 一个 web 服务, 没有开始 分布式链路追踪的功能, 但是,每个请求都有 requestId 的字段,期望将 requestId 设置到 日志中, 用于快速定位日志 Describe the solution you'd like 增加一个 Hook 的接口, 或者运行时的回调函数,让用户可以设置多个回调函数或者不同逻辑的 hook 接口 Describe alternatives you've considered
Additional context 接口或者方法 必须参数是 context.Context y以方便通过 ctx 来传输上下文, 然后返回值是一组 logx.Field logx 在打印日志之前, 自动执行这些回调的方法用于获取业务的动态字段
At present, logx already provides similar functions. You can try to use logx.WithFields/logx.ContextWithFields to pass fields to context. You can build this process in middleware.
At present, logx already provides similar functions. You can try to use logx.WithFields/logx.ContextWithFields to pass fields to context. You can build this process in middleware.
At present, logx already provides similar functions. You can try to use logx.WithFields/logx.ContextWithFields to pass fields to context. You can build this process in middleware.
logx extract trace_id and span_id function is hard code, as like extract span_id function, we just pass value by context, and use plugins to extract the value then inject it into to log