本文整理匯總了Golang中github.com/mitchellh/panicwrap.WrapConfig.Writer方法的典型用法代碼示例。如果您正苦於以下問題:Golang WrapConfig.Writer方法的具體用法?Golang WrapConfig.Writer怎麽用?Golang WrapConfig.Writer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mitchellh/panicwrap.WrapConfig
的用法示例。
在下文中一共展示了WrapConfig.Writer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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()
}
示例2: 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()
}
示例3: 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()
}
示例4: 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()
}