Skip to content

Commit

Permalink
Drop icingadb#Register() & make mysqlLogger exportable
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Mar 27, 2024
1 parent 081c4de commit cf6c6f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) {
}
}

icingadb.Register(logger)
_ = mysql.SetLogger(icingadb.MysqlFuncLogger(logger.Debug))

c, err := mysql.NewConnector(config)
if err != nil {
Expand Down
12 changes: 3 additions & 9 deletions pkg/icingadb/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package icingadb
import (
"context"
"database/sql/driver"
"github.com/go-sql-driver/mysql"
"github.com/icinga/icingadb/pkg/backoff"
"github.com/icinga/icingadb/pkg/icingaredis/telemetry"
"github.com/icinga/icingadb/pkg/logging"
Expand Down Expand Up @@ -82,16 +81,11 @@ func (c RetryConnector) Driver() driver.Driver {
return c.Connector.Driver()
}

// Register sets the default mysql logger to the given one.
func Register(logger *logging.Logger) {
_ = mysql.SetLogger(mysqlLogger(logger.Debug))
}

// mysqlLogger is an adapter that allows ordinary functions to be used as a logger for mysql.SetLogger.
type mysqlLogger func(v ...interface{})
// MysqlFuncLogger is an adapter that allows ordinary functions to be used as a logger for mysql.SetLogger.
type MysqlFuncLogger func(v ...interface{})

// Print implements the mysql.Logger interface.
func (log mysqlLogger) Print(v ...interface{}) {
func (log MysqlFuncLogger) Print(v ...interface{}) {
log(v)
}

Expand Down

0 comments on commit cf6c6f6

Please sign in to comment.