diff --git a/cmd/execute.go b/cmd/execute.go index e8b5e513..2fe6007f 100644 --- a/cmd/execute.go +++ b/cmd/execute.go @@ -17,7 +17,6 @@ package cmd import ( "fmt" - "os" "plugin" syn "sync" "time" @@ -82,7 +81,7 @@ func execute() { log.Info("linking plugin", pluginPath) plug, err := plugin.Open(pluginPath) if err != nil { - log.Debug("linking plugin failed") + log.Warn("linking plugin failed") log.Fatal(err) } @@ -90,15 +89,14 @@ func execute() { log.Info("loading transformers from plugin") symExporter, err := plug.Lookup("Exporter") if err != nil { - log.Debug("loading Exporter symbol failed") + log.Warn("loading Exporter symbol failed") log.Fatal(err) } // Assert that the symbol is of type Exporter exporter, ok := symExporter.(Exporter) if !ok { - log.Debug("plugged-in symbol not of type Exporter") - os.Exit(1) + log.Fatal("plugged-in symbol not of type Exporter") } // Use the Exporters export method to load the EventTransformerInitializer, StorageTransformerInitializer, and ContractTransformerInitializer sets diff --git a/cmd/fullSync.go b/cmd/fullSync.go index 4d29c43a..803b37d5 100644 --- a/cmd/fullSync.go +++ b/cmd/fullSync.go @@ -96,7 +96,7 @@ func fullSync() { if err != nil { log.Error("fullSync: error in validateBlocks: ", err) } - log.Info(window.GetString()) + log.Debug(window.GetString()) case <-missingBlocksPopulated: go backFillAllBlocks(blockChain, blockRepository, missingBlocksPopulated, startingBlockNumber) } diff --git a/cmd/headerSync.go b/cmd/headerSync.go index e4840ba6..f24a045c 100644 --- a/cmd/headerSync.go +++ b/cmd/headerSync.go @@ -88,7 +88,7 @@ func headerSync() { if err != nil { log.Error("headerSync: ValidateHeaders failed: ", err) } - log.Info(window.GetString()) + log.Debug(window.GetString()) case n := <-missingBlocksPopulated: if n == 0 { time.Sleep(3 * time.Second) diff --git a/cmd/root.go b/cmd/root.go index ef2475db..69890a9d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,7 +18,6 @@ package cmd import ( "fmt" - "os" "strings" "time" @@ -56,17 +55,22 @@ const ( var rootCmd = &cobra.Command{ Use: "vulcanizedb", - PersistentPreRun: database, + PersistentPreRun: initFuncs, } func Execute() { log.Info("----- Starting vDB -----") if err := rootCmd.Execute(); err != nil { log.Fatal(err) - os.Exit(1) } } +func initFuncs(cmd *cobra.Command, args []string) { + database(cmd, args) + logLevel(cmd, args) + +} + func database(cmd *cobra.Command, args []string) { ipc = viper.GetString("client.ipcpath") levelDbPath = viper.GetString("client.leveldbpath") @@ -81,6 +85,16 @@ func database(cmd *cobra.Command, args []string) { viper.Set("database.config", databaseConfig) } +func logLevel(cmd *cobra.Command, args []string) error { + lvl, err := log.ParseLevel(viper.GetString("log.level")) + if err != nil { + return err + } + log.SetLevel(lvl) + log.Info("Log level set to ", lvl.String()) + return nil +} + func init() { cobra.OnInitialize(initConfig) // When searching for env variables, replace dots in config keys with underscores @@ -97,6 +111,7 @@ func init() { rootCmd.PersistentFlags().String("client-levelDbPath", "", "location of levelDb chaindata") rootCmd.PersistentFlags().String("filesystem-storageDiffsPath", "", "location of storage diffs csv file") rootCmd.PersistentFlags().String("exporter-name", "exporter", "name of exporter plugin") + rootCmd.PersistentFlags().String("log-level", log.InfoLevel.String(), "Log level (trace, debug, info, warn, error, fatal, panic") viper.BindPFlag("database.name", rootCmd.PersistentFlags().Lookup("database-name")) viper.BindPFlag("database.port", rootCmd.PersistentFlags().Lookup("database-port")) @@ -107,6 +122,7 @@ func init() { viper.BindPFlag("client.levelDbPath", rootCmd.PersistentFlags().Lookup("client-levelDbPath")) viper.BindPFlag("filesystem.storageDiffsPath", rootCmd.PersistentFlags().Lookup("filesystem-storageDiffsPath")) viper.BindPFlag("exporter.fileName", rootCmd.PersistentFlags().Lookup("exporter-name")) + viper.BindPFlag("log.level", rootCmd.PersistentFlags().Lookup("log-level")) } func initConfig() { @@ -116,7 +132,6 @@ func initConfig() { noConfigError := "No config file passed with --config flag" fmt.Println("Error: ", noConfigError) log.Fatal(noConfigError) - os.Exit(1) } if err := viper.ReadInConfig(); err == nil { @@ -125,7 +140,6 @@ func initConfig() { invalidConfigError := "Couldn't read config file" fmt.Println("Error: ", invalidConfigError) log.Fatal(invalidConfigError) - os.Exit(1) } } diff --git a/libraries/shared/fetcher/storage_fetcher.go b/libraries/shared/fetcher/storage_fetcher.go index dea891e8..48960dcf 100644 --- a/libraries/shared/fetcher/storage_fetcher.go +++ b/libraries/shared/fetcher/storage_fetcher.go @@ -17,9 +17,12 @@ package fetcher import ( + "strings" + + log "github.com/sirupsen/logrus" + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" "github.com/vulcanize/vulcanizedb/pkg/fs" - "strings" ) type IStorageFetcher interface { @@ -39,6 +42,7 @@ func (storageFetcher CsvTailStorageFetcher) FetchStorageDiffs(out chan<- utils.S if tailErr != nil { errs <- tailErr } + log.Debug("fetching storage diffs...") for line := range t.Lines { row, parseErr := utils.FromStrings(strings.Split(line.Text, ",")) if parseErr != nil { diff --git a/pkg/history/populate_blocks.go b/pkg/history/populate_blocks.go index a2c542d0..9651dd51 100644 --- a/pkg/history/populate_blocks.go +++ b/pkg/history/populate_blocks.go @@ -17,6 +17,7 @@ package history import ( + "fmt" log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/core" @@ -35,7 +36,7 @@ func PopulateMissingBlocks(blockchain core.BlockChain, blockRepository datastore return 0, nil } - log.Printf("Backfilling %d blocks\n\n", len(blockRange)) + log.Debug(getBlockRangeString(blockRange)) _, err = RetrieveAndUpdateBlocks(blockchain, blockRepository, blockRange) if err != nil { log.Error("PopulateMissingBlocks: error gettings/updating blocks: ", err) @@ -61,3 +62,7 @@ func RetrieveAndUpdateBlocks(blockchain core.BlockChain, blockRepository datasto } return len(blockNumbers), nil } + +func getBlockRangeString(blockRange []int64) string { + return fmt.Sprintf("Backfilling |%v| blocks", len(blockRange)) +} diff --git a/pkg/history/populate_headers.go b/pkg/history/populate_headers.go index dd8028ce..f2abc93b 100644 --- a/pkg/history/populate_headers.go +++ b/pkg/history/populate_headers.go @@ -39,7 +39,7 @@ func PopulateMissingHeaders(blockChain core.BlockChain, headerRepository datasto return 0, nil } - log.Printf("Backfilling %d blocks\n\n", len(blockNumbers)) + log.Debug(getBlockRangeString(blockNumbers)) _, err = RetrieveAndUpdateHeaders(blockChain, headerRepository, blockNumbers) if err != nil { log.Error("PopulateMissingHeaders: Error getting/updating headers:", err) @@ -61,3 +61,4 @@ func RetrieveAndUpdateHeaders(blockChain core.BlockChain, headerRepository datas } return len(blockNumbers), nil } + diff --git a/pkg/history/validation_window.go b/pkg/history/validation_window.go index 24ae5ff0..92e360ad 100644 --- a/pkg/history/validation_window.go +++ b/pkg/history/validation_window.go @@ -50,6 +50,6 @@ func MakeRange(min, max int64) []int64 { } func (window ValidationWindow) GetString() string { - return fmt.Sprintf("Validating Blocks |%v|-- Validation Window --|%v}|", + return fmt.Sprintf("Validating Blocks |%v|-- Validation Window --|%v|", window.LowerBound, window.UpperBound) }