From 04cd5eeb91389eef2ed85b0451505304e776d8a3 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 3 Sep 2017 19:19:28 -0400 Subject: [PATCH] refactor: move all logging functions to their own file --- plugins/common/common.go | 37 ----------------------------------- plugins/common/log.go | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 plugins/common/log.go diff --git a/plugins/common/common.go b/plugins/common/common.go index eae0e0df0..d9cba64ef 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -93,13 +93,6 @@ func MustGetEnv(key string) string { return value } -// LogFail is the failure log formatter -// prints text to stderr and exits with status 1 -func LogFail(text string) { - fmt.Fprintln(os.Stderr, fmt.Sprintf("FAILED: %s", text)) - os.Exit(1) -} - // GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName string) { if appName == "" { @@ -311,35 +304,6 @@ func IsImageHerokuishBased(image string) bool { return dockerCmd.Execute() } -// LogInfo1 is the info1 header formatter -func LogInfo1(text string) { - fmt.Fprintln(os.Stdout, fmt.Sprintf("-----> %s", text)) -} - -// LogInfo1Quiet is the info1 header formatter (with quiet option) -func LogInfo1Quiet(text string) { - if os.Getenv("DOKKU_QUIET_OUTPUT") != "" { - LogInfo1(text) - } -} - -// LogInfo2 is the info2 header formatter -func LogInfo2(text string) { - fmt.Fprintln(os.Stdout, fmt.Sprintf("=====> %s", text)) -} - -// LogInfo2Quiet is the info2 header formatter (with quiet option) -func LogInfo2Quiet(text string) { - if os.Getenv("DOKKU_QUIET_OUTPUT") != "" { - LogInfo2(text) - } -} - -// LogWarn is the warning log formatter -func LogWarn(text string) { - fmt.Fprintln(os.Stderr, fmt.Sprintf(" ! %s", text)) -} - // ReadFirstLine gets the first line of a file that has contents and returns it // if there are no contents, an empty string is returned // will also return an empty string if the file does not exist @@ -362,7 +326,6 @@ func ReadFirstLine(filename string) string { return text } return "" - } // StripInlineComments removes bash-style comment from input line diff --git a/plugins/common/log.go b/plugins/common/log.go new file mode 100644 index 000000000..132822328 --- /dev/null +++ b/plugins/common/log.go @@ -0,0 +1,42 @@ +package common + +import ( + "fmt" + "os" +) + +// LogFail is the failure log formatter +// prints text to stderr and exits with status 1 +func LogFail(text string) { + fmt.Fprintln(os.Stderr, fmt.Sprintf("FAILED: %s", text)) + os.Exit(1) +} + +// LogInfo1 is the info1 header formatter +func LogInfo1(text string) { + fmt.Fprintln(os.Stdout, fmt.Sprintf("-----> %s", text)) +} + +// LogInfo1Quiet is the info1 header formatter (with quiet option) +func LogInfo1Quiet(text string) { + if os.Getenv("DOKKU_QUIET_OUTPUT") != "" { + LogInfo1(text) + } +} + +// LogInfo2 is the info2 header formatter +func LogInfo2(text string) { + fmt.Fprintln(os.Stdout, fmt.Sprintf("=====> %s", text)) +} + +// LogInfo2Quiet is the info2 header formatter (with quiet option) +func LogInfo2Quiet(text string) { + if os.Getenv("DOKKU_QUIET_OUTPUT") != "" { + LogInfo2(text) + } +} + +// LogWarn is the warning log formatter +func LogWarn(text string) { + fmt.Fprintln(os.Stderr, fmt.Sprintf(" ! %s", text)) +}