diff --git a/node/node.go b/node/node.go index ac8dc5e5f0..59f903c75a 100644 --- a/node/node.go +++ b/node/node.go @@ -1949,14 +1949,14 @@ func (app *App) setupDBs(ctx context.Context, lg log.Log) error { if err := os.MkdirAll(dbPath, os.ModePerm); err != nil { return fmt.Errorf("failed to create %s: %w", dbPath, err) } - dbLog := app.addLogger(StateDbLogger, lg) - m21 := migrations.New0021Migration(dbLog.Zap(), 1_000_000) + dbLog := app.addLogger(StateDbLogger, lg).Zap() + m21 := migrations.New0021Migration(dbLog, 1_000_000) migrations, err := sql.StateMigrations() if err != nil { return fmt.Errorf("failed to load migrations: %w", err) } dbopts := []sql.Opt{ - sql.WithLogger(dbLog.Zap()), + sql.WithLogger(dbLog), sql.WithMigrations(migrations), sql.WithMigration(m21), sql.WithConnections(app.Config.DatabaseConnections), @@ -2010,7 +2010,7 @@ func (app *App) setupDBs(ctx context.Context, lg log.Log) error { return fmt.Errorf("load local migrations: %w", err) } localDB, err := localsql.Open("file:"+filepath.Join(dbPath, localDbFile), - sql.WithLogger(dbLog.Zap()), + sql.WithLogger(dbLog), sql.WithMigrations(migrations), sql.WithConnections(app.Config.DatabaseConnections), ) diff --git a/sql/metrics/prometheus.go b/sql/metrics/prometheus.go index 6a7ba2ef5f..30991749b1 100644 --- a/sql/metrics/prometheus.go +++ b/sql/metrics/prometheus.go @@ -6,9 +6,9 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" "golang.org/x/sync/errgroup" - "github.com/spacemeshos/go-spacemesh/log" "github.com/spacemeshos/go-spacemesh/metrics" "github.com/spacemeshos/go-spacemesh/sql" ) @@ -20,7 +20,7 @@ const ( // DBMetricsCollector collects metrics from db. type DBMetricsCollector struct { - logger log.Logger + logger *zap.Logger checkInterval time.Duration db *sql.Database tablesList map[string]struct{} @@ -36,13 +36,13 @@ type DBMetricsCollector struct { func NewDBMetricsCollector( ctx context.Context, db *sql.Database, - logger log.Logger, + logger *zap.Logger, checkInterval time.Duration, ) *DBMetricsCollector { ctx, cancel := context.WithCancel(ctx) collector := &DBMetricsCollector{ checkInterval: checkInterval, - logger: logger.WithName("db_metrics"), + logger: logger.Named("db_metrics"), db: db, cancel: cancel, tableSize: metrics.NewGauge("table_size", subsystem, "Size of table in bytes", []string{"name"}), @@ -51,20 +51,20 @@ func NewDBMetricsCollector( } statEnabled, err := collector.checkCompiledWithDBStat() if err != nil { - collector.logger.With().Error("error check compile options", log.Err(err)) + collector.logger.Error("error check compile options", zap.Error(err)) return nil } if !statEnabled { - collector.logger.With().Info("sqlite compiled without `SQLITE_ENABLE_DBSTAT_VTAB`. Metrics will not collected") + collector.logger.Info("sqlite compiled without `SQLITE_ENABLE_DBSTAT_VTAB`. Metrics will not collected") return nil } collector.tablesList, err = collector.getListOfTables() if err != nil { - collector.logger.With().Error("error get list of tables", log.Err(err)) + collector.logger.Error("error get list of tables", zap.Error(err)) return nil } - collector.logger.With().Info("start collect stat") + collector.logger.Info("start collect stat") collector.eg.Go(func() error { collector.CollectMetrics(ctx) return nil @@ -76,7 +76,7 @@ func NewDBMetricsCollector( func (d *DBMetricsCollector) Close() { d.cancel() if err := d.eg.Wait(); err != nil { - d.logger.With().Error("received error waiting for db metrics collector", log.Err(err)) + d.logger.Error("received error waiting for db metrics collector", zap.Error(err)) } } @@ -89,7 +89,7 @@ func (d *DBMetricsCollector) CollectMetrics(ctx context.Context) { case <-ticker.C: d.logger.Debug("collect stats from db") if err := d.collect(); err != nil { - d.logger.With().Error("error check db metrics", log.Err(err)) + d.logger.Error("error collecting db metrics", zap.Error(err)) } case <-ctx.Done(): return