Skip to content

Configurable logger per connection #1405

Closed

Description

@frozenbonito

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)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions