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

Please change the input parameter type of SetDefaultLogger to ILogger #3156

Closed
shuqingzai opened this issue Nov 14, 2023 · 4 comments
Closed

Comments

@shuqingzai
Copy link

#2704 ,不理解回复中的强制不允许修改是为什么?可以说明一下理由吗??理论上,用户应该是可以自定义Log,既然有接口 ,比如:我们需要将日志的写入与输出格式统一化为 zap ,方便上层统一采集,现在无法实现

1. What version of Go and system type/arch are you using?

# -> % go version
go version go1.21.3 darwin/amd64

2. What version of GoFrame are you using?

# -> % gf version
GoFrame CLI Tool v2.5.6, https://goframe.org
GoFrame Version: v2.5.6 in current go.mod

3. Can this issue be re-produced with the latest release?

是的

4. What did you do?

5. What did you expect to see?

6. What did you see instead?

@Issues-translate-bot Issues-translate-bot changed the title 请将 SetDefaultLogger 的输入参数类型更改为 ILogger Please change the input parameter type of SetDefaultLogger to ILogger Nov 14, 2023
@wln32
Copy link
Member

wln32 commented Mar 15, 2024

func handlerLog(ctx context.Context, in *glog.HandlerInput) {
	fmt.Println(in.Values...)
}

func main() {
	glog.SetDefaultHandler(handlerLog)
	glog.Info(nil, "hello worold", "666")
}

貌似可以用这种方法来实现,HandlerInput有调用info error panic方法的一些信息

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


func handlerLog(ctx context.Context, in *glog.HandlerInput) {
fmt.Println(in.Values...)
}

func main() {
glog.SetDefaultHandler(handlerLog)
glog.Info(nil, "hello worold", "666")
}

It seems that this method can be used. HandlerInput has some information about calling the info error panic method.

@gqcn
Copy link
Member

gqcn commented Oct 7, 2024

@shuqingzai @wln32
不好意思,我来晚了,由于邮件丢失我错过了一些issue的消息提示。

这里的glog.SetDefaultLogger仅针对glog组件生效,用于修改glog组件公开包方法使用的默认glog.Logger对象,这样通过glog.Xxx或者g.Log().Xxx可以使用该*glog.Logger对象。

由于glog.Logger的功能特性比较多,因此不支持使用通用日志接口的形式来设置日志组件本身的默认使用对象。通用日志接口的方式仅适用于其他组件包,并且该组件包仅仅会使用某几个日志打印方法且没有用到高级日志特性的场景下适用,例如gdb/gcron/polaris等组件。其实这些组件应该用到什么接口才定义什么接口,且不应该直接使用glog.ILogger

如果想使用第三方的日志组件可以参考前面 @wln32 提供的方式来设置自定义的日志打印逻辑。

感谢大家❤️

@gqcn gqcn added the question label Oct 7, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@shuqingzai @wln32
Sorry, I'm late. I missed some issue messages due to lost emails.
The glog.SetDefaultLogger here is only effective for the glog component and is used to modify the default glog.Logger object used by the glog component public package method, so that it is passed glog.Xxx or g.Log(). Xxx can use the *glog.Logger object.
Since glog.Logger has many functions and features, it does not support setting in the form of a general log interface. The general log interface method is only applicable to other component packages. For example, this component package only uses certain log printing methods and Applicable to scenarios where advanced logging features are not used.
If you want to use a third-party log component, you can refer to the method provided by @wln32 to set up custom log printing logic.
Thank you everyone❤️

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

No branches or pull requests

4 participants