Prettify console output message (#1396)

This commit is contained in:
Ta-Ching Chen
2019-11-10 16:42:34 +08:00
committed by GitHub
parent 7b6e4318d4
commit 7640f1199d
7 changed files with 51 additions and 35 deletions
+11 -2
View File
@@ -19,6 +19,7 @@ package console
import (
"fmt"
"os"
"strings"
"github.com/life1347/color"
)
@@ -28,12 +29,16 @@ var (
Verbosity int
)
func Error(msg interface{}) {
os.Stderr.WriteString(fmt.Sprintf("%v: %v\n", color.RedString("Error"), trimNewline(msg)))
}
func Warn(msg interface{}) {
os.Stdout.WriteString(fmt.Sprintf("%v: %v\n", color.YellowString("Warning"), msg))
os.Stdout.WriteString(fmt.Sprintf("%v: %v\n", color.YellowString("Warning"), trimNewline(msg)))
}
func Info(msg interface{}) {
os.Stderr.WriteString(fmt.Sprintf("%v\n", msg))
os.Stderr.WriteString(fmt.Sprintf("%v\n", trimNewline(msg)))
}
func Verbose(verbosityLevel int, format string, args ...interface{}) {
@@ -41,3 +46,7 @@ func Verbose(verbosityLevel int, format string, args ...interface{}) {
fmt.Printf(format+"\n", args...)
}
}
func trimNewline(m interface{}) string {
return strings.TrimSuffix(fmt.Sprintf("%v", m), "\n")
}