Beispiel #1
0
// SetupLogging will initialize the logger backend and set the flags.
func SetupLogging(w io.Writer) {
	if w != nil {
		Underlying.Out = io.MultiWriter(os.Stderr, w)
	}
	if runtime.GOOS == "windows" { // colored ttys are rare on windows...
		Underlying.Formatter = &logrus.TextFormatter{DisableColors: true}
	}
	if lvl := os.Getenv("CRYPTIX_LOGLVL"); lvl != "" {
		l, err := logrus.ParseLevel(lvl)
		if err != nil {
			logrus.Errorf("logging: could not parse lvl from env, defaulting to debug: %s", err)
			l = logrus.DebugLevel
		}
		Underlying.Level = l
	}
}
Beispiel #2
0
// CheckFatal exits the process if err != nil
func CheckFatal(err error) {
	if err != nil {
		pc, file, line, ok := runtime.Caller(1)
		if !ok {
			file = "?"
			line = 0
		}
		fn := runtime.FuncForPC(pc)
		var fnName string
		if fn == nil {
			fnName = "?()"
		} else {
			dotName := filepath.Ext(fn.Name())
			fnName = strings.TrimLeft(dotName, ".") + "()"
		}
		logrus.Errorf("%s:%d %s", file, line, fnName)
		logrus.Error("Fatal Error:", errgo.Details(err))
		if closeChan != nil {
			logrus.Warn("Sending close message")
			closeChan <- os.Interrupt
		}
		os.Exit(1)
	}
}