pulumi/pkg/util/contract/failfast.go
joeduffy e14ca5f4ff Manually print the stack-trace when --logtostderr is enabled
Glog doesn't actually print out the stack traces for all goroutines,
when --logtostderr is enabled, the same way it normally does.  This
makes debugging more complex in some cases.  So, we'll manually do it.
2017-02-09 14:50:41 -08:00

25 lines
576 B
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package contract
import (
"flag"
"fmt"
"os"
"runtime/debug"
"github.com/golang/glog"
)
// failfast logs and panics the process in a way that is friendly to debugging.
func failfast(msg string) {
v := flag.Lookup("logtostderr").Value
if g, isgettable := v.(flag.Getter); isgettable {
if enabled := g.Get().(bool); enabled {
// Print the stack to stderr anytime glog verbose logging is enabled, since glog won't.
fmt.Fprintf(os.Stderr, "fatal: %v\n", msg)
debug.PrintStack()
}
}
glog.Fatal(msg)
}