From e6e6333e6dfeed41f7f709c7cba0ca66e39a29aa Mon Sep 17 00:00:00 2001
From: patelpayal <payal.patel99@gmail.com>
Date: Mon, 1 Jul 2019 01:49:46 -0700
Subject: [PATCH] add glog flush to write the output to a file (#329)

* add glog flush to write the output to a file

* add glog flush before exit on error and fix code comment
---
 cmd/root.go | 4 ++++
 cmd/util.go | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/cmd/root.go b/cmd/root.go
index 41973fd..04011f8 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -74,8 +74,12 @@ func Execute() {
 
 	if err := RootCmd.Execute(); err != nil {
 		fmt.Println(err)
+		// flush before exit non-zero
+		glog.Flush()
 		os.Exit(-1)
 	}
+	// flush before exit
+	glog.Flush()
 }
 
 func init() {
diff --git a/cmd/util.go b/cmd/util.go
index fcb537f..c63295c 100644
--- a/cmd/util.go
+++ b/cmd/util.go
@@ -35,6 +35,8 @@ func init() {
 
 func exitWithError(err error) {
 	fmt.Fprintf(os.Stderr, "\n%v\n", err)
+	// flush before exit non-zero
+	glog.Flush()
 	os.Exit(1)
 }
 
-- 
GitLab