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


Golang panicwrap.Wrap函數代碼示例

本文整理匯總了Golang中github.com/mitchellh/panicwrap.Wrap函數的典型用法代碼示例。如果您正苦於以下問題:Golang Wrap函數的具體用法?Golang Wrap怎麽用?Golang Wrap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: defaultPanicHandler

// NOTE: this function does not return when you call it, instead it
// re-exec()s the current process with panic monitoring.
func defaultPanicHandler() {
	defer defaultNotifier.dontPanic()

	exitStatus, err := panicwrap.Wrap(&panicwrap.WrapConfig{
		CookieKey:   "bugsnag_wrapped",
		CookieValue: "bugsnag_wrapped",
		Handler: func(output string) {

			toNotify, err := errors.ParsePanic(output)

			if err != nil {
				defaultNotifier.Config.log("bugsnag.handleUncaughtPanic: %v", err)
			}
			Notify(toNotify, SeverityError, Configuration{Synchronous: true})
		},
	})

	if err != nil {
		defaultNotifier.Config.log("bugsnag.handleUncaughtPanic: %v", err)
		return
	}

	if exitStatus >= 0 {
		os.Exit(exitStatus)
	} else {
		return
	}
}
開發者ID:kyrylo,項目名稱:bugsnag-go,代碼行數:30,代碼來源:panicwrap.go

示例2: realMain

func realMain() int {
	var wrapConfig panicwrap.WrapConfig

	if !panicwrap.Wrapped(&wrapConfig) {
		// Determine where logs should go in general (requested by the user)
		logWriter, err := logOutput()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
			return 1
		}
		if logWriter == nil {
			logWriter = ioutil.Discard
		}

		// We always send logs to a temporary file that we use in case
		// there is a panic. Otherwise, we delete it.
		logTempFile, err := ioutil.TempFile("", "terraform-log")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't setup logging tempfile: %s", err)
			return 1
		}
		defer os.Remove(logTempFile.Name())
		defer logTempFile.Close()

		// Tell the logger to log to this file
		os.Setenv(EnvLog, "")
		os.Setenv(EnvLogFile, "")

		// Setup the prefixed readers that send data properly to
		// stdout/stderr.
		outR, outW := io.Pipe()
		go copyOutput(outR)

		// Create the configuration for panicwrap and wrap our executable
		wrapConfig.Handler = panicHandler(logTempFile)
		wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter)
		wrapConfig.Stdout = outW
		exitStatus, err := panicwrap.Wrap(&wrapConfig)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't start Terraform: %s", err)
			return 1
		}

		// If >= 0, we're the parent, so just exit
		if exitStatus >= 0 {
			return exitStatus
		}

		// We're the child, so just close the tempfile we made in order to
		// save file handles since the tempfile is only used by the parent.
		logTempFile.Close()
	}

	// Call the real main
	return wrappedMain()
}
開發者ID:JasonGiedymin,項目名稱:terraform,代碼行數:56,代碼來源:main.go

示例3: realMain

// realMain is executed from main and returns the exit status to exit with.
func realMain() int {
	// If there is no explicit number of Go threads to use, then set it
	if os.Getenv("GOMAXPROCS") == "" {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}

	// Determine where logs should go in general (requested by the user)
	logWriter, err := logOutput()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
		return 1
	}

	// We also always send logs to a temporary file that we use in case
	// there is a panic. Otherwise, we delete it.
	logTempFile, err := ioutil.TempFile("", "packer-log")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't setup logging tempfile: %s", err)
		return 1
	}
	defer os.Remove(logTempFile.Name())
	defer logTempFile.Close()

	// Reset the log variables to minimize work in the subprocess
	os.Setenv("PACKER_LOG", "")
	os.Setenv("PACKER_LOG_FILE", "")

	// Create the configuration for panicwrap and wrap our executable
	wrapConfig := &panicwrap.WrapConfig{
		Handler: panicHandler(logTempFile),
		Writer:  io.MultiWriter(logTempFile, logWriter),
	}

	exitStatus, err := panicwrap.Wrap(wrapConfig)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't start Packer: %s", err)
		return 1
	}

	if exitStatus >= 0 {
		return exitStatus
	}

	// We're the child, so just close the tempfile we made in order to
	// save file handles since the tempfile is only used by the parent.
	logTempFile.Close()

	return wrappedMain()
}
開發者ID:EdevMosaic,項目名稱:packer,代碼行數:50,代碼來源:packer.go

示例4: realMain

func realMain() int {
	var wrapConfig panicwrap.WrapConfig

	// don't re-exec terraform as a child process for easier debugging
	if os.Getenv("TF_FORK") == "0" {
		return wrappedMain()
	}

	if !panicwrap.Wrapped(&wrapConfig) {
		// Determine where logs should go in general (requested by the user)
		logWriter, err := logging.LogOutput()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
			return 1
		}

		// We always send logs to a temporary file that we use in case
		// there is a panic. Otherwise, we delete it.
		logTempFile, err := ioutil.TempFile("", "terraform-log")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't setup logging tempfile: %s", err)
			return 1
		}
		defer os.Remove(logTempFile.Name())
		defer logTempFile.Close()

		// Setup the prefixed readers that send data properly to
		// stdout/stderr.
		doneCh := make(chan struct{})
		outR, outW := io.Pipe()
		go copyOutput(outR, doneCh)

		// Create the configuration for panicwrap and wrap our executable
		wrapConfig.Handler = panicHandler(logTempFile)
		wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter)
		wrapConfig.Stdout = outW
		exitStatus, err := panicwrap.Wrap(&wrapConfig)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't start Terraform: %s", err)
			return 1
		}

		// If >= 0, we're the parent, so just exit
		if exitStatus >= 0 {
			// Close the stdout writer so that our copy process can finish
			outW.Close()

			// Wait for the output copying to finish
			<-doneCh

			return exitStatus
		}

		// We're the child, so just close the tempfile we made in order to
		// save file handles since the tempfile is only used by the parent.
		logTempFile.Close()
	}

	// Call the real main
	return wrappedMain()
}
開發者ID:mhlias,項目名稱:terraform,代碼行數:61,代碼來源:main.go

示例5: realMain

func realMain() int {
	// Set a custom panicwrap cookie key and value. Since we're executing
	// other panicwrap executables, the default cookie key/value cause
	// weird errors if we don't change them.
	var wrapConfig panicwrap.WrapConfig
	wrapConfig.CookieKey = "OTTO_PANICWRAP_COOKIE"
	wrapConfig.CookieValue = fmt.Sprintf(
		"otto-%s-%s-%s", Version, VersionPrerelease, GitCommit)

	if !panicwrap.Wrapped(&wrapConfig) {
		// Determine where logs should go in general (requested by the user)
		logWriter, err := logOutput()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
			return 1
		}
		if logWriter == nil {
			logWriter = ioutil.Discard
		}

		// We always send logs to a temporary file that we use in case
		// there is a panic. Otherwise, we delete it.
		logTempFile, err := ioutil.TempFile("", "otto-log")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't setup logging tempfile: %s", err)
			return 1
		}
		defer os.Remove(logTempFile.Name())
		defer logTempFile.Close()

		// Tell the logger to log to this file
		os.Setenv(EnvLog, "")
		os.Setenv(EnvLogFile, "")

		// Setup the prefixed readers that send data properly to
		// stdout/stderr.
		doneCh := make(chan struct{})
		outR, outW := io.Pipe()
		go copyOutput(outR, doneCh)

		// Create the configuration for panicwrap and wrap our executable
		wrapConfig.Handler = panicHandler(logTempFile)
		wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter)
		wrapConfig.Stdout = outW
		exitStatus, err := panicwrap.Wrap(&wrapConfig)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't start Otto: %s", err)
			return 1
		}

		// If >= 0, we're the parent, so just exit
		if exitStatus >= 0 {
			// Close the stdout writer so that our copy process can finish
			outW.Close()

			// Wait for the output copying to finish
			<-doneCh

			return exitStatus
		}

		// We're the child, so just close the tempfile we made in order to
		// save file handles since the tempfile is only used by the parent.
		logTempFile.Close()
	}

	// Call the real main
	return wrappedMain()
}
開發者ID:mbrodala,項目名稱:otto,代碼行數:69,代碼來源:main.go

示例6: realMain

func realMain() int {
	//使用panicwrap封裝panic
	var wrapConfig panicwrap.WrapConfig
	wrapConfig.CookieKey = "OTTO_PANICWRAP_COOKIE"
	wrapConfig.CookieValue = fmt.Sprintf("otto-%s-%s-%s", Version, VersionPrerelease, GitCommit)
	//fmt.Printf("warpConfig : %+v\n", wrapConfig)

	if !panicwrap.Wrapped(&wrapConfig) {
		fmt.Println("沒有封裝wrapConfig配置")
		logWriter, err := logOutput()
		if err != nil {
			fmt.Fprintf(os.Stderr, "不能設置Log輸出到:%s", err)
			return 1
		}
		if logWriter == nil {
			logWriter = ioutil.Discard //Discard實現了io.Writer接口
		}

		//當發生panic時我們發送log到臨時文件,否則就刪除
		logTempFile, err := ioutil.TempFile("", "kuuyee-otto-log")
		if err != nil {
			fmt.Fprintf(os.Stderr, "不能設置Log臨時文件:%s", err)
			return 1
		}
		defer os.Remove(logTempFile.Name())
		defer logTempFile.Close()

		// 告訴logger把日誌輸出到這個文件
		os.Setenv(Envlog, "")
		os.Setenv(EnvLogFile, "")

		// 設置發送到stdout/stderr數據的讀取前綴
		doneCh := make(chan struct{})
		outR, outW := io.Pipe()
		go copyOutput(outR, doneCh)

		// 創建panicwrap配置
		wrapConfig.Handler = panicHandler(logTempFile)
		wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter)
		wrapConfig.Stdout = outW
		exitStatus, err := panicwrap.Wrap(&wrapConfig)
		if err != nil {
			fmt.Fprintf(os.Stderr, "不能啟動Otto: %s", err)
			return 1
		}

		// 如果>=0,那麽我們是父進程,所以退出
		if exitStatus >= 0 {
			outW.Close()

			<-doneCh

			return exitStatus
		}

		// 我們是子,所以關閉tempfile
		logTempFile.Close()

	}

	fmt.Printf("[KuuYee_DEBUG]====> %s\n", "main.go/realMain/81")
	//調用真正的main函數
	return wrappedMain()
}
開發者ID:kuuyee,項目名稱:otto-learn,代碼行數:64,代碼來源:main.go


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