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

Is it possible to pass a logger interface to enable custom logger instance? #619

Closed
greenhat616 opened this issue Sep 14, 2023 · 2 comments
Labels

Comments

@greenhat616
Copy link

Despite Go's poor design in not providing a standard Logger interface, we can still achieve a unified Logger instance by customizing the Logger interface. For example, I prefer using JSON logs for easy log collection.

Example

type Logger interface {
	Debugw(msg string, fields ...interface{})
	Infow(msg string, fields ...interface{})
	Warnw(msg string, fields ...interface{})
	Errorw(msg string, fields ...interface{})
}

Later on, you only need to provide a Logger option when creating the robot (we can implement the Logger interface you require), and you can provide a default logger implementation at creation. I believe such changes are not very invasive.

@TheOrdinaryWow
Copy link

Indeed, it'd be quite useful if zap could be introduced as logger instead of using the built-in log.

@demget
Copy link
Collaborator

demget commented Nov 19, 2023

All the log calls are adjustable: you can write your own middleware for logging incoming requests with the logger package you like. There is also a Bot.OnError field to override the error-handler.

@demget demget closed this as completed Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants