Closed
Description
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)
Metadata
Metadata
Assignees
Labels
No labels