aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils/cmd.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-05-27 21:48:07 +0800
committerFelix Lange <fjl@twurst.com>2015-05-28 07:09:26 +0800
commit705beb4c25f976f6bce40818bd835e235c2babf4 (patch)
treeab3080032074bbc8d3f944b685fa40a4ca86504c /cmd/utils/cmd.go
parent74706a0f029fe74ea15e366904d827da03091fef (diff)
downloadgo-tangerine-705beb4c25f976f6bce40818bd835e235c2babf4.tar
go-tangerine-705beb4c25f976f6bce40818bd835e235c2babf4.tar.gz
go-tangerine-705beb4c25f976f6bce40818bd835e235c2babf4.tar.bz2
go-tangerine-705beb4c25f976f6bce40818bd835e235c2babf4.tar.lz
go-tangerine-705beb4c25f976f6bce40818bd835e235c2babf4.tar.xz
go-tangerine-705beb4c25f976f6bce40818bd835e235c2babf4.tar.zst
go-tangerine-705beb4c25f976f6bce40818bd835e235c2babf4.zip
cmd/utils: print errors only once if stdout and stderr are the same file
Diffstat (limited to 'cmd/utils/cmd.go')
-rw-r--r--cmd/utils/cmd.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 550ac1c51..06c240bd4 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -125,10 +125,17 @@ func initDataDir(Datadir string) {
}
}
-// Fatalf formats a message to standard output and exits the program.
+// Fatalf formats a message to standard error and exits the program.
+// The message is also printed to standard output if standard error
+// is redirected to a different file.
func Fatalf(format string, args ...interface{}) {
- fmt.Fprintf(os.Stderr, "Fatal: "+format+"\n", args...)
- fmt.Fprintf(os.Stdout, "Fatal: "+format+"\n", args...)
+ w := io.MultiWriter(os.Stdout, os.Stderr)
+ outf, _ := os.Stdout.Stat()
+ errf, _ := os.Stderr.Stat()
+ if outf != nil && errf != nil && os.SameFile(outf, errf) {
+ w = os.Stderr
+ }
+ fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
logger.Flush()
os.Exit(1)
}