diff --git a/cmd/resync.go b/cmd/resync.go
index d61feff9..723e88fa 100644
--- a/cmd/resync.go
+++ b/cmd/resync.go
@@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
"github.com/vulcanize/vulcanizedb/pkg/super_node/resync"
+ v "github.com/vulcanize/vulcanizedb/version"
)
// resyncCmd represents the resync command
@@ -41,6 +42,8 @@ func rsyncCmdCommand() {
if err != nil {
logWithCommand.Fatal(err)
}
+ logWithCommand.Infof("vdb version: %s", v.VersionWithMeta)
+ logWithCommand.Infof("resync config: %+v", rConfig)
if err := ipfs.InitIPFSPlugins(); err != nil {
logWithCommand.Fatal(err)
}
diff --git a/cmd/root.go b/cmd/root.go
index 056329bd..054e4284 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -19,6 +19,7 @@ package cmd
import (
"errors"
"fmt"
+ "os"
"strings"
"time"
@@ -69,11 +70,23 @@ func Execute() {
func initFuncs(cmd *cobra.Command, args []string) {
setViperConfigs()
- logLvlErr := logLevel()
- if logLvlErr != nil {
- log.Fatal("Could not set log level: ", logLvlErr)
+ logfile := viper.GetString("logfile")
+ if logfile != "" {
+ file, err := os.OpenFile(logfile,
+ os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
+ if err == nil {
+ log.Infof("Directing output to %s", logfile)
+ log.SetOutput(file)
+ } else {
+ log.SetOutput(os.Stdout)
+ log.Info("Failed to log to file, using default stdout")
+ }
+ } else {
+ log.SetOutput(os.Stdout)
+ }
+ if err := logLevel(); err != nil {
+ log.Fatal("Could not set log level: ", err)
}
-
}
func setViperConfigs() {
@@ -140,18 +153,13 @@ func init() {
func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
+ if err := viper.ReadInConfig(); err == nil {
+ log.Printf("Using config file: %s", viper.ConfigFileUsed())
+ } else {
+ log.Fatal(fmt.Sprintf("Couldn't read config file: %s", err.Error()))
+ }
} else {
- noConfigError := "No config file passed with --config flag"
- fmt.Println("Error: ", noConfigError)
- log.Fatal(noConfigError)
- }
-
- if err := viper.ReadInConfig(); err == nil {
- log.Printf("Using config file: %s\n\n", viper.ConfigFileUsed())
- } else {
- invalidConfigError := "Couldn't read config file"
- formattedError := fmt.Sprintf("%s: %s", invalidConfigError, err.Error())
- log.Fatal(formattedError)
+ log.Warn("No config file passed with --config flag")
}
}
diff --git a/cmd/superNode.go b/cmd/superNode.go
index f9e8ae31..6e13bac0 100644
--- a/cmd/superNode.go
+++ b/cmd/superNode.go
@@ -27,6 +27,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
"github.com/vulcanize/vulcanizedb/pkg/super_node"
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
+ v "github.com/vulcanize/vulcanizedb/version"
)
// superNodeCmd represents the superNode command
@@ -56,6 +57,8 @@ func superNode() {
if err != nil {
logWithCommand.Fatal(err)
}
+ logWithCommand.Infof("vdb version: %s", v.VersionWithMeta)
+ logWithCommand.Infof("super node config: %+v", superNodeConfig)
if err := ipfs.InitIPFSPlugins(); err != nil {
logWithCommand.Fatal(err)
}
diff --git a/cmd/version.go b/cmd/version.go
new file mode 100644
index 00000000..cc35f32e
--- /dev/null
+++ b/cmd/version.go
@@ -0,0 +1,41 @@
+// Copyright © 2020 Vulcanize, Inc
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package cmd
+
+import (
+ log "github.com/sirupsen/logrus"
+ "github.com/spf13/cobra"
+
+ v "github.com/vulcanize/vulcanizedb/version"
+)
+
+// versionCmd represents the version command
+var versionCmd = &cobra.Command{
+ Use: "version",
+ Short: "Prints the version of vulcanizeDB",
+ Long: `Use this command to fetch the version of vulcanizeDB
+
+Usage: ./vulcanizedb version`,
+ Run: func(cmd *cobra.Command, args []string) {
+ subCommand = cmd.CalledAs()
+ logWithCommand = *log.WithField("SubCommand", subCommand)
+ logWithCommand.Infof("VulcanizeDB version: %s", v.VersionWithMeta)
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(versionCmd)
+}
diff --git a/main.go b/main.go
index 7bfdd290..ca125800 100644
--- a/main.go
+++ b/main.go
@@ -1,10 +1,6 @@
package main
import (
- "os"
-
- "github.com/spf13/viper"
-
"github.com/vulcanize/vulcanizedb/cmd"
"github.com/sirupsen/logrus"
@@ -14,18 +10,5 @@ func main() {
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
- logfile := viper.GetString("logfile")
- if logfile != "" {
- file, err := os.OpenFile(logfile,
- os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
- if err == nil {
- logrus.SetOutput(file)
- } else {
- logrus.SetOutput(os.Stdout)
- logrus.Info("Failed to log to file, using default stdout")
- }
- } else {
- logrus.SetOutput(os.Stdout)
- }
cmd.Execute()
}
diff --git a/pkg/super_node/api.go b/pkg/super_node/api.go
index 8d33eadd..ff74cdde 100644
--- a/pkg/super_node/api.go
+++ b/pkg/super_node/api.go
@@ -28,6 +28,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/super_node/btc"
"github.com/vulcanize/vulcanizedb/pkg/super_node/eth"
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
+ v "github.com/vulcanize/vulcanizedb/version"
)
// APIName is the namespace used for the state diffing service API
@@ -141,5 +142,5 @@ func (iapi *InfoAPI) NodeInfo() *p2p.NodeInfo {
// Version returns the version of the super node
func (iapi *InfoAPI) Version() string {
- return VersionWithMeta
+ return v.VersionWithMeta
}
diff --git a/pkg/super_node/version.go b/version/version.go
similarity index 61%
rename from pkg/super_node/version.go
rename to version/version.go
index a85bb41f..88631b1a 100644
--- a/pkg/super_node/version.go
+++ b/version/version.go
@@ -14,14 +14,14 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-package super_node
+package version
import "fmt"
const (
- VersionMajor = 0 // Major version component of the current release
- VersionMinor = 1 // Minor version component of the current release
- VersionPatch = 0 // Patch version component of the current release
+ VersionMajor = 0 // Major version component of the current release
+ VersionMinor = 1 // Minor version component of the current release
+ VersionPatch = 0 // Patch version component of the current release
VersionMeta = "alpha" // Version metadata to append to the version string
)
@@ -38,26 +38,3 @@ var VersionWithMeta = func() string {
}
return v
}()
-
-// ArchiveVersion holds the textual version string
-func ArchiveVersion(gitCommit string) string {
- vsn := Version
- if VersionMeta != "stable" {
- vsn += "-" + VersionMeta
- }
- if len(gitCommit) >= 8 {
- vsn += "-" + gitCommit[:8]
- }
- return vsn
-}
-
-func VersionWithCommit(gitCommit, gitDate string) string {
- vsn := VersionWithMeta
- if len(gitCommit) >= 8 {
- vsn += "-" + gitCommit[:8]
- }
- if (VersionMeta != "stable") && (gitDate != "") {
- vsn += "-" + gitDate
- }
- return vsn
-}