Remove injection of SubCommand for logs

This commit is contained in:
Andrew J Yao
2019-07-23 13:11:20 -07:00
parent a188e1dd79
commit ee77fc6521
13 changed files with 102 additions and 93 deletions
+15 -14
View File
@@ -105,7 +105,8 @@ single config file or in separate command instances using different config files
Specify config location when executing the command:
./vulcanizedb composeAndExecute --config=./environments/config_name.toml`,
Run: func(cmd *cobra.Command, args []string) {
subCommand = cmd.CalledAs()
SubCommand = cmd.CalledAs()
LogWithCommand = *log.WithField("SubCommand", SubCommand)
composeAndExecute()
},
}
@@ -115,44 +116,44 @@ func composeAndExecute() {
prepConfig()
// Generate code to build the plugin according to the config file
log.WithField("subCommand", subCommand).Info("generating plugin")
LogWithCommand.Info("generating plugin")
generator, err := p2.NewGenerator(genConfig, databaseConfig)
if err != nil {
log.WithField("subCommand", subCommand).Fatal(err)
LogWithCommand.Fatal(err)
}
err = generator.GenerateExporterPlugin()
if err != nil {
log.WithField("subCommand", subCommand).Debug("generating plugin failed")
log.WithField("subCommand", subCommand).Fatal(err)
LogWithCommand.Debug("generating plugin failed")
LogWithCommand.Fatal(err)
}
// Get the plugin path and load the plugin
_, pluginPath, err := genConfig.GetPluginPaths()
if err != nil {
log.WithField("subCommand", subCommand).Fatal(err)
LogWithCommand.Fatal(err)
}
if !genConfig.Save {
defer helpers.ClearFiles(pluginPath)
}
log.WithField("subCommand", subCommand).Info("linking plugin", pluginPath)
LogWithCommand.Info("linking plugin ", pluginPath)
plug, err := plugin.Open(pluginPath)
if err != nil {
log.WithField("subCommand", subCommand).Debug("linking plugin failed")
log.WithField("subCommand", subCommand).Fatal(err)
LogWithCommand.Debug("linking plugin failed")
LogWithCommand.Fatal(err)
}
// Load the `Exporter` symbol from the plugin
log.WithField("subCommand", subCommand).Info("loading transformers from plugin")
LogWithCommand.Info("loading transformers from plugin")
symExporter, err := plug.Lookup("Exporter")
if err != nil {
log.WithField("subCommand", subCommand).Debug("loading Exporter symbol failed")
log.WithField("subCommand", subCommand).Fatal(err)
LogWithCommand.Debug("loading Exporter symbol failed")
LogWithCommand.Fatal(err)
}
// Assert that the symbol is of type Exporter
exporter, ok := symExporter.(Exporter)
if !ok {
log.WithField("subCommand", subCommand).Debug("plugged-in symbol not of type Exporter")
LogWithCommand.Debug("plugged-in symbol not of type Exporter")
os.Exit(1)
}
@@ -160,7 +161,7 @@ func composeAndExecute() {
ethEventInitializers, ethStorageInitializers, ethContractInitializers := exporter.Export()
// Setup bc and db objects
blockChain := getBlockChain(subCommand)
blockChain := getBlockChain()
db := utils.LoadPostgres(databaseConfig, blockChain.Node())
// Execute over transformer sets returned by the exporter