// initParms handles the initialization of `parms`. func (c *counters) initParms(stub *shim.ChaincodeStub, args []string) (val []byte, err error) { c.infof("initParms : Command-line arguments : %v", args) // Define and parse the parameters flags := flag.NewFlagSet("initParms", flag.ContinueOnError) flags.StringVar(&c.id, "id", "", "A unique identifier; Allows multiple copies of this chaincode to be deployed") loggingLevel := flags.String("loggingLevel", "default", "The logging level of the chaincode logger. Defaults to INFO.") shimLoggingLevel := flags.String("shimLoggingLevel", "default", "The logging level of the chaincode 'shim' interface. Defaults to WARNING.") flags.BoolVar(&c.checkCounters, "checkCounters", false, "Default false. If true, consistency checks are made on counter states during increment/decrement.") flags.BoolVar(&c.checkStatus, "checkStatus", true, "Default true; If false, no error/consistency checks are made in the 'status' method.") err = flags.Parse(args) if err != nil { c.errorf("initParms : Error during option processing : %s", err) } // Replace the original logger logging as "counters", with a new logger, // then set its logging level and the logging level of the shim. c.logger = shim.NewLogger("counters:" + c.id) if *loggingLevel == "default" { c.logger.SetLevel(shim.LogInfo) } else { level, _ := shim.LogLevel(*loggingLevel) c.logger.SetLevel(level) } if *shimLoggingLevel != "default" { level, _ := shim.LogLevel(*shimLoggingLevel) shim.SetLoggingLevel(level) } return }
// initParms handles the initialization of `parms`. func (c *counters) initParms(args []string) (val []byte, err error) { c.infof("initParms : Command-line arguments : %v", args) // Define and parse the parameters flags := flag.NewFlagSet("initParms", flag.ContinueOnError) flags.StringVar(&c.id, "id", "", "A unique identifier; Allows multiple copies of this chaincode to be deployed") loggingLevel := flags.String("loggingLevel", "default", "The logging level of the chaincode logger. Defaults to INFO.") shimLoggingLevel := flags.String("shimLoggingLevel", "default", "The logging level of the chaincode 'shim' interface. Defaults to WARNING.") err = flags.Parse(args) if err != nil { c.errorf("initParms : Error during option processing : %s", err) } // Replace the original logger, logging as "counters", with a new logger // logging as "counters:<id>", then set its logging level and the logging // level of the shim. c.logger = shim.NewLogger("counters:" + c.id) if *loggingLevel == "default" { c.logger.SetLevel(shim.LogInfo) } else { level, _ := shim.LogLevel(*loggingLevel) c.logger.SetLevel(level) } if *shimLoggingLevel != "default" { level, _ := shim.LogLevel(*shimLoggingLevel) shim.SetLoggingLevel(level) } return }