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

Configurable logger per connection #1405

Closed
frozenbonito opened this issue Mar 12, 2023 · 0 comments · Fixed by #1408
Closed

Configurable logger per connection #1405

frozenbonito opened this issue Mar 12, 2023 · 0 comments · Fixed by #1408

Comments

@frozenbonito
Copy link
Contributor

frozenbonito commented Mar 12, 2023

Issue description

This is a feature proposal.
This library can only use global logger on package level, so different loggers cannot be used separately for each database or test.
It would be useful to be able to configure a logger per connection.

Related: #593 (comment)

Example code

For example, add a field to Config like this:

type Config struct {
	// ...

	ErrLog Logger
}

If ErrLog is nil, it fallbacks to the package global logger (errLog).

I'm not sure if adding it to the Config is a good idea since the ErrLog cannot be included into a DSN string.
Alternatively, I think there is a way to add parameters for configuration to NewConnector.

func NewConnector(cfg *Config, options ...Option) (driver.Connector, error) {
	// ...
}

type Option interface {
	apply(*connector)
}

func LoggerOption(logger Logger) Option {
	// ...
}

It would be nice to add a function like the following to support ErrLog in a DSN string.

func RegisterLogger(name string, logger Logger)
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

Successfully merging a pull request may close this issue.

1 participant