github.com/Consensys/quorum@v21.1.0+incompatible/raft/util.go (about)

     1  package raft
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"os"
     7  	"runtime"
     8  )
     9  
    10  // TODO: this is just copied over from cmd/utils/cmd.go. dedupe
    11  
    12  // Fatalf formats a message to standard error and exits the program.
    13  // The message is also printed to standard output if standard error
    14  // is redirected to a different file.
    15  func fatalf(format string, args ...interface{}) {
    16  	w := io.MultiWriter(os.Stdout, os.Stderr)
    17  	if runtime.GOOS == "windows" {
    18  		// The SameFile check below doesn't work on Windows.
    19  		// stdout is unlikely to get redirected though, so just print there.
    20  		w = os.Stdout
    21  	} else {
    22  		outf, _ := os.Stdout.Stat()
    23  		errf, _ := os.Stderr.Stat()
    24  		if outf != nil && errf != nil && os.SameFile(outf, errf) {
    25  			w = os.Stderr
    26  		}
    27  	}
    28  	fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
    29  	os.Exit(1)
    30  }