Refactor logger (#3924)

This patch fixes below

* Previously fatalIf() never writes log other than first logging target.
* quiet flag is not honored to show progress messages other than startup messages.
* Removes console package usage for progress messages.
This commit is contained in:
Bala FA
2017-03-24 05:06:00 +05:30
committed by Harshavardhana
parent 11e15f9b4c
commit d3cb79a57c
18 changed files with 450 additions and 426 deletions

View File

@@ -30,7 +30,6 @@ import (
"github.com/fatih/color"
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
)
// Check for new software updates.
@@ -111,9 +110,7 @@ func isDocker(cgroupFile string) (bool, error) {
// IsDocker - returns if the environment is docker or not.
func IsDocker() bool {
found, err := isDocker("/proc/self/cgroup")
if err != nil {
console.Fatalf("Error in docker check: %s", err)
}
fatalIf(err, "Error in docker check.")
return found
}
@@ -263,25 +260,23 @@ func mainUpdate(ctx *cli.Context) {
}
quiet := ctx.Bool("quiet") || ctx.GlobalBool("quiet")
quietPrintln := func(args ...interface{}) {
if !quiet {
console.Println(args...)
}
if quiet {
log.EnableQuiet()
}
minioMode := ""
older, downloadURL, err := getUpdateInfo(10*time.Second, minioMode)
if err != nil {
quietPrintln(err)
log.Println(err)
os.Exit(-1)
}
if older != time.Duration(0) {
quietPrintln(colorizeUpdateMessage(downloadURL, older))
log.Println(colorizeUpdateMessage(downloadURL, older))
os.Exit(1)
}
colorSprintf := color.New(color.FgGreen, color.Bold).SprintfFunc()
quietPrintln(colorSprintf("You are already running the most recent version of minio."))
log.Println(colorSprintf("You are already running the most recent version of minio."))
os.Exit(0)
}