當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Logger.SetLevel方法代碼示例

本文整理匯總了Golang中github.com/koding/logging.Logger.SetLevel方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.SetLevel方法的具體用法?Golang Logger.SetLevel怎麽用?Golang Logger.SetLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/koding/logging.Logger的用法示例。


在下文中一共展示了Logger.SetLevel方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SSHCommandFactory

// SSHCommandFactory is the factory method for SSHCommand.
func SSHCommandFactory(c *cli.Context, log logging.Logger, _ string) int {
	if len(c.Args()) != 1 {
		cli.ShowCommandHelp(c, "ssh")
		return 1
	}

	if c.Bool("debug") {
		log.SetLevel(logging.DEBUG)
	}

	opts := ssh.SSHCommandOpts{
		Debug:          c.Bool("debug") || config.Konfig.Debug,
		RemoteUsername: c.String("username"),
		Ask:            true,
	}
	cmd, err := ssh.NewSSHCommand(log, opts)
	mountName := c.Args()[0]

	// TODO: Refactor SSHCommand instance to require no initialization,
	// and thus avoid needing to log an error in a weird place.
	if err != nil {
		log.Error("Error initializing ssh: %s", err)
		switch err {
		case ssh.ErrLocalDialingFailed:
			fmt.Println(
				defaultHealthChecker.CheckAllFailureOrMessagef(KlientIsntRunning),
			)
		default:
			fmt.Println(GenericInternalError)
		}

		metrics.TrackSSHFailed(mountName, err.Error(), config.VersionNum())
		return 1
	}

	now := time.Now()

	// track metrics
	go func() {
		metrics.TrackSSH(mountName, config.VersionNum())
	}()

	err = cmd.Run(mountName)
	switch err {
	case nil:
		metrics.TrackSSHEnd(mountName, "", -now.Sub(now).Minutes(), config.VersionNum())
		return 0
	case ssh.ErrMachineNotFound:
		fmt.Println(MachineNotFound)
	case ssh.ErrCannotFindUser:
		fmt.Println(CannotFindSSHUser)
		metrics.TrackSSHFailed(mountName, err.Error(), config.VersionNum())
	case ssh.ErrFailedToGetSSHKey:
		fmt.Println(FailedGetSSHKey)
		metrics.TrackSSHFailed(mountName, err.Error(), config.VersionNum())
	case ssh.ErrMachineNotValidYet:
		fmt.Println(defaultHealthChecker.CheckAllFailureOrMessagef(MachineNotValidYet))
		metrics.TrackSSHFailed(mountName, err.Error(), config.VersionNum())
	case ssh.ErrRemoteDialingFailed:
		fmt.Println(defaultHealthChecker.CheckAllFailureOrMessagef(FailedDialingRemote))
		metrics.TrackSSHFailed(mountName, err.Error(), config.VersionNum())
	case shortcut.ErrMachineNotFound:
		fmt.Println(MachineNotFound)
		metrics.TrackSSHFailed(mountName, err.Error(), config.VersionNum())
	}

	log.Error("SSHCommand.Run returned err:%s", err)

	// ssh returns `exit status 255` on disconnection; so we also send how long
	// session has been running for to indicate if ssh was successful at least
	// once and the failed due to disconnection
	metrics.TrackSSHEnd(mountName, err.Error(), -now.Sub(now).Minutes(), config.VersionNum())

	return 1
}
開發者ID:,項目名稱:,代碼行數:76,代碼來源:


注:本文中的github.com/koding/logging.Logger.SetLevel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。