Skip to content

Commit

Permalink
[FAB-9074] Init logging prior to MSP
Browse files Browse the repository at this point in the history
Move MSP initialization after logging
initialization for all commands

Change-Id: I8a9271424b62fef0b70b9daf10ba8c6b04654006
Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
  • Loading branch information
mastersingh24 committed May 13, 2018
1 parent f1133ad commit 89c0b3b
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions peer/main.go
Expand Up @@ -34,23 +34,7 @@ const cmdRoot = "core"
// The main command describes the service and
// defaults to printing the help message.
var mainCmd = &cobra.Command{
Use: "peer",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// check for --logging-level pflag first, which should override all other
// log settings. if --logging-level is not set, use CORE_LOGGING_LEVEL
// (environment variable takes priority; otherwise, the value set in
// core.yaml)
var loggingSpec string
if viper.GetString("logging_level") != "" {
loggingSpec = viper.GetString("logging_level")
} else {
loggingSpec = viper.GetString("logging.level")
}
flogging.InitFromSpec(loggingSpec)

return nil
},
}
Use: "peer"}

func main() {
// For environment variables.
Expand Down Expand Up @@ -78,11 +62,21 @@ func main() {
os.Exit(1)
}

runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))

// setup system-wide logging backend based on settings from core.yaml
flogging.InitBackend(flogging.SetFormat(viper.GetString("logging.format")), logOutput)

// check for --logging-level pflag first, which should override all other
// log settings. if --logging-level is not set, use CORE_LOGGING_LEVEL
// (environment variable takes priority; otherwise, the value set in
// core.yaml)
var loggingSpec string
if viper.GetString("logging_level") != "" {
loggingSpec = viper.GetString("logging_level")
} else {
loggingSpec = viper.GetString("logging.level")
}
flogging.InitFromSpec(loggingSpec)

// Init the MSP
var mspMgrConfigDir = config.GetPath("peer.mspConfigPath")
var mspID = viper.GetString("peer.localMspId")
Expand All @@ -95,6 +89,9 @@ func main() {
logger.Errorf("Cannot run peer because %s", err.Error())
os.Exit(1)
}

runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))

// On failure Cobra prints the usage message and error string, so we only
// need to exit with a non-0 status
if mainCmd.Execute() != nil {
Expand Down

0 comments on commit 89c0b3b

Please sign in to comment.