github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/peer/clilogging/revertlevels.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 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  	"golang.org/x/net/context"
    21  
    22  	"github.com/golang/protobuf/ptypes/empty"
    23  
    24  	"github.com/spf13/cobra"
    25  )
    26  
    27  func revertLevelsCmd(cf *LoggingCmdFactory) *cobra.Command {
    28  	var loggingRevertLevelsCmd = &cobra.Command{
    29  		Use:   "revertlevels",
    30  		Short: "Reverts the logging levels to the levels at the end of peer startup.",
    31  		Long:  `Reverts the logging levels to the levels at the end of peer startup`,
    32  		RunE: func(cmd *cobra.Command, args []string) error {
    33  			return revertLevels(cf, cmd, args)
    34  		},
    35  	}
    36  	return loggingRevertLevelsCmd
    37  }
    38  
    39  func revertLevels(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  		_, err = cf.AdminClient.RevertLogLevels(context.Background(), &empty.Empty{})
    49  		if err != nil {
    50  			return err
    51  		}
    52  		logger.Info("Log levels reverted to the levels at the end of peer startup.")
    53  	}
    54  	return err
    55  }