Skip to content

Commit 89c0b3b

Browse files
committed
[FAB-9074] Init logging prior to MSP
Move MSP initialization after logging initialization for all commands Change-Id: I8a9271424b62fef0b70b9daf10ba8c6b04654006 Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent f1133ad commit 89c0b3b

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

peer/main.go

+16-19
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,7 @@ const cmdRoot = "core"
3434
// The main command describes the service and
3535
// defaults to printing the help message.
3636
var mainCmd = &cobra.Command{
37-
Use: "peer",
38-
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
39-
// check for --logging-level pflag first, which should override all other
40-
// log settings. if --logging-level is not set, use CORE_LOGGING_LEVEL
41-
// (environment variable takes priority; otherwise, the value set in
42-
// core.yaml)
43-
var loggingSpec string
44-
if viper.GetString("logging_level") != "" {
45-
loggingSpec = viper.GetString("logging_level")
46-
} else {
47-
loggingSpec = viper.GetString("logging.level")
48-
}
49-
flogging.InitFromSpec(loggingSpec)
50-
51-
return nil
52-
},
53-
}
37+
Use: "peer"}
5438

5539
func main() {
5640
// For environment variables.
@@ -78,11 +62,21 @@ func main() {
7862
os.Exit(1)
7963
}
8064

81-
runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))
82-
8365
// setup system-wide logging backend based on settings from core.yaml
8466
flogging.InitBackend(flogging.SetFormat(viper.GetString("logging.format")), logOutput)
8567

68+
// check for --logging-level pflag first, which should override all other
69+
// log settings. if --logging-level is not set, use CORE_LOGGING_LEVEL
70+
// (environment variable takes priority; otherwise, the value set in
71+
// core.yaml)
72+
var loggingSpec string
73+
if viper.GetString("logging_level") != "" {
74+
loggingSpec = viper.GetString("logging_level")
75+
} else {
76+
loggingSpec = viper.GetString("logging.level")
77+
}
78+
flogging.InitFromSpec(loggingSpec)
79+
8680
// Init the MSP
8781
var mspMgrConfigDir = config.GetPath("peer.mspConfigPath")
8882
var mspID = viper.GetString("peer.localMspId")
@@ -95,6 +89,9 @@ func main() {
9589
logger.Errorf("Cannot run peer because %s", err.Error())
9690
os.Exit(1)
9791
}
92+
93+
runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))
94+
9895
// On failure Cobra prints the usage message and error string, so we only
9996
// need to exit with a non-0 status
10097
if mainCmd.Execute() != nil {

0 commit comments

Comments
 (0)