Skip to content

Commit

Permalink
Add way to control MSP logging on peer at startup
Browse files Browse the repository at this point in the history
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 <wtlahti@us.ibm.com>
  • Loading branch information
wlahti committed Jan 31, 2017
1 parent c7b3fe0 commit 89f726a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion peer/clilogging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var loggingCmd = &cobra.Command{
// note: for code running on the peer, this level is set during peer startup
// in peer/node/start.go and can be updated dynamically using
// "peer logging setlevel error <log-level>"
return common.SetErrorLoggingLevel()
return common.SetLogLevelFromViper("error")
},
Short: fmt.Sprintf("%s specific commands.", loggingFuncName),
Long: fmt.Sprintf("%s specific commands.", loggingFuncName),
Expand Down
12 changes: 7 additions & 5 deletions peer/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ func GetAdminClient() (pb.AdminClient, error) {
return adminClient, nil
}

// SetErrorLoggingLevel sets the 'error' module's logger to the value in
// SetLogLevelFromViper sets the log level for 'module' logger to the value in
// core.yaml
func SetErrorLoggingLevel() error {
viperErrorLoggingLevel := viper.GetString("logging.error")
_, err := flogging.SetModuleLevel("error", viperErrorLoggingLevel)

func SetLogLevelFromViper(module string) error {
var err error
if module != "" {
logLevelFromViper := viper.GetString("logging." + module)
_, err = flogging.SetModuleLevel(module, logLevelFromViper)
}
return err
}

Expand Down
1 change: 1 addition & 0 deletions peer/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ logging:
version: warning
protoutils: debug
error: warning
msp: warning

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

Expand Down
9 changes: 5 additions & 4 deletions peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ func serve(args []string) error {
}()
}

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

// Block until grpc server exits
return <-serve
Expand Down

0 comments on commit 89f726a

Please sign in to comment.