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
+18 -15
View File
@@ -101,7 +101,8 @@ single config file or in separate command instances using different config files
Specify config location when executing the command:
./vulcanizedb compose --config=./environments/config_name.toml`,
Run: func(cmd *cobra.Command, args []string) {
subCommand = cmd.CalledAs()
SubCommand = cmd.CalledAs()
LogWithCommand = *log.WithField("SubCommand", SubCommand)
compose()
},
}
@@ -111,23 +112,25 @@ func compose() {
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.Debug("initializing plugin generator failed")
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)
}
// TODO: Embed versioning info in the .so files so we know which version of vulcanizedb to run them with
_, pluginPath, err := genConfig.GetPluginPaths()
if err != nil {
log.WithField("subCommand", subCommand).Fatal(err)
LogWithCommand.Debug("getting plugin path failed")
LogWithCommand.Fatal(err)
}
fmt.Printf("Composed plugin %s", pluginPath)
log.WithField("subCommand", subCommand).Info("plugin .so file output to", pluginPath)
LogWithCommand.Info("plugin .so file output to ", pluginPath)
}
func init() {
@@ -135,38 +138,38 @@ func init() {
}
func prepConfig() {
log.WithField("subCommand", subCommand).Info("configuring plugin")
LogWithCommand.Info("configuring plugin")
names := viper.GetStringSlice("exporter.transformerNames")
transformers := make(map[string]config.Transformer)
for _, name := range names {
transformer := viper.GetStringMapString("exporter." + name)
p, pOK := transformer["path"]
if !pOK || p == "" {
log.WithField("subCommand", subCommand).Fatal(name, "transformer config is missing `path` value")
LogWithCommand.Fatal(name, " transformer config is missing `path` value")
}
r, rOK := transformer["repository"]
if !rOK || r == "" {
log.WithField("subCommand", subCommand).Fatal(name, "transformer config is missing `repository` value")
LogWithCommand.Fatal(name, " transformer config is missing `repository` value")
}
m, mOK := transformer["migrations"]
if !mOK || m == "" {
log.WithField("subCommand", subCommand).Fatal(name, "transformer config is missing `migrations` value")
LogWithCommand.Fatal(name, " transformer config is missing `migrations` value")
}
mr, mrOK := transformer["rank"]
if !mrOK || mr == "" {
log.WithField("subCommand", subCommand).Fatal(name, "transformer config is missing `rank` value")
LogWithCommand.Fatal(name, " transformer config is missing `rank` value")
}
rank, err := strconv.ParseUint(mr, 10, 64)
if err != nil {
log.WithField("subCommand", subCommand).Fatal(name, "migration `rank` can't be converted to an unsigned integer")
LogWithCommand.Fatal(name, " migration `rank` can't be converted to an unsigned integer")
}
t, tOK := transformer["type"]
if !tOK {
log.WithField("subCommand", subCommand).Fatal(name, "transformer config is missing `type` value")
LogWithCommand.Fatal(name, " transformer config is missing `type` value")
}
transformerType := config.GetTransformerType(t)
if transformerType == config.UnknownTransformerType {
log.WithField("subCommand", subCommand).Fatal(errors.New(`unknown transformer type in exporter config accepted types are "eth_event", "eth_storage"`))
LogWithCommand.Fatal(errors.New(`unknown transformer type in exporter config accepted types are "eth_event", "eth_storage"`))
}
transformers[name] = config.Transformer{