github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/peer/clilogging/getlevel.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package clilogging 18 19 import ( 20 pb "github.com/hyperledger/fabric/protos/peer" 21 22 "github.com/spf13/cobra" 23 "golang.org/x/net/context" 24 ) 25 26 func getLevelCmd(cf *LoggingCmdFactory) *cobra.Command { 27 var loggingGetLevelCmd = &cobra.Command{ 28 Use: "getlevel <module>", 29 Short: "Returns the logging level of the requested module logger.", 30 Long: `Returns the logging level of the requested module logger. Note: the module name should exactly match the name that is displayed in the logs.`, 31 RunE: func(cmd *cobra.Command, args []string) error { 32 return getLevel(cf, cmd, args) 33 }, 34 } 35 36 return loggingGetLevelCmd 37 } 38 39 func getLevel(cf *LoggingCmdFactory, cmd *cobra.Command, args []string) (err error) { 40 err = checkLoggingCmdParams(cmd, args) 41 if err == nil { 42 if cf == nil { 43 cf, err = InitCmdFactory() 44 if err != nil { 45 return err 46 } 47 } 48 logResponse, err := cf.AdminClient.GetModuleLogLevel(context.Background(), &pb.LogLevelRequest{LogModule: args[0]}) 49 if err != nil { 50 return err 51 } 52 logger.Infof("Current log level for peer module '%s': %s", logResponse.LogModule, logResponse.LogLevel) 53 } 54 return err 55 }