From c3150e06a90fcf5e6004b7e102c9bcc307fc2f60 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Wed, 9 Jan 2019 10:05:16 +0100 Subject: [PATCH] package logger --- db/sqlite.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/db/sqlite.go b/db/sqlite.go index c7e98f0..4e3bd58 100644 --- a/db/sqlite.go +++ b/db/sqlite.go @@ -7,6 +7,11 @@ import ( "time" ) +var log *logrus.Entry +func init(){ + log = logrus.WithFields(logrus.Fields{"prefix": "db/sqlite.Migrate"}) +} + const migrateScript = ` alter table blocks add mtime timestamp default NULL; update blocks set mtime = current_timestamp; @@ -29,7 +34,6 @@ type Sqlite3Accessor struct { } func (db *Sqlite3Accessor) Migrate() error { - log := logrus.WithFields(logrus.Fields{"prefix": "db/sqlite.Migrate","filename":db.filename}) //RW connection rwdb, err := sql.Open("sqlite3", db.filename + "?mode=rw") @@ -46,7 +50,7 @@ func (db *Sqlite3Accessor) Migrate() error { } if !hasMtime { - log.Info("Migrating database") + log.WithFields(logrus.Fields{"filename":db.filename}).Info("Migrating database") start := time.Now() _, err = rwdb.Exec(migrateScript) if err != nil {