Skip to content

Commit 89f726a

Browse files
committed
Add way to control MSP logging on peer at startup
This CR adds a parameter to peer/core.yaml, logging.msp, which can be used to change the log level for the msp module on the peer at startup. https://jira.hyperledger.org/browse/FAB-1870 Change-Id: I3f47e06c09fa9d7d945d303ba0420ab1024ddc19 Signed-off-by: Will Lahti <[email protected]>
1 parent c7b3fe0 commit 89f726a

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

peer/clilogging/logging.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var loggingCmd = &cobra.Command{
4747
// note: for code running on the peer, this level is set during peer startup
4848
// in peer/node/start.go and can be updated dynamically using
4949
// "peer logging setlevel error <log-level>"
50-
return common.SetErrorLoggingLevel()
50+
return common.SetLogLevelFromViper("error")
5151
},
5252
Short: fmt.Sprintf("%s specific commands.", loggingFuncName),
5353
Long: fmt.Sprintf("%s specific commands.", loggingFuncName),

peer/common/common.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ func GetAdminClient() (pb.AdminClient, error) {
104104
return adminClient, nil
105105
}
106106

107-
// SetErrorLoggingLevel sets the 'error' module's logger to the value in
107+
// SetLogLevelFromViper sets the log level for 'module' logger to the value in
108108
// core.yaml
109-
func SetErrorLoggingLevel() error {
110-
viperErrorLoggingLevel := viper.GetString("logging.error")
111-
_, err := flogging.SetModuleLevel("error", viperErrorLoggingLevel)
112-
109+
func SetLogLevelFromViper(module string) error {
110+
var err error
111+
if module != "" {
112+
logLevelFromViper := viper.GetString("logging." + module)
113+
_, err = flogging.SetModuleLevel(module, logLevelFromViper)
114+
}
113115
return err
114116
}
115117

peer/core.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ logging:
3636
version: warning
3737
protoutils: debug
3838
error: warning
39+
msp: warning
3940

4041
format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
4142

peer/node/start.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,11 @@ func serve(args []string) error {
230230
}()
231231
}
232232

233-
// sets the logging level for the 'error' module to the default value from
234-
// core.yaml. it can also be updated dynamically using
235-
// "peer logging setlevel error <log-level>"
236-
common.SetErrorLoggingLevel()
233+
// sets the logging level for the 'error' and 'msp' modules to the
234+
// values from core.yaml. they can also be updated dynamically using
235+
// "peer logging setlevel <module-name> <log-level>"
236+
common.SetLogLevelFromViper("error")
237+
common.SetLogLevelFromViper("msp")
237238

238239
// Block until grpc server exits
239240
return <-serve

0 commit comments

Comments
 (0)