diff --git a/util/util.go b/util/util.go index 2a9a7c7..b4050e1 100644 --- a/util/util.go +++ b/util/util.go @@ -5,6 +5,7 @@ package util import ( "errors" + "fmt" "log" "os" "strings" @@ -22,6 +23,8 @@ func CreateFolder(path string) error { var err error if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) { + printUtil("creating folder : " + path + " (if not exists)") + err = os.Mkdir(path, os.ModePerm) if err != nil { log.Println(err) @@ -37,6 +40,8 @@ func CreatePath(path string) error { var err error if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) { + printUtil("creating path : " + path + " (if not exists)") + err = os.MkdirAll(path, os.ModePerm) if err != nil { log.Println(err) @@ -45,3 +50,22 @@ func CreatePath(path string) error { return err } + +func getUtilLogPrefix() string { + return " ***  util: " +} + +func fmtUtilOut(input string) string { + return getUtilLogPrefix() + input +} + +func printUtil(input string) { + if _, err := fmt.Fprintln(os.Stderr, fmtUtilOut(input)); err != nil { + fmt.Fprintf( + os.Stdout, + getUtilLogPrefix(), + "error while printing to stderr: %q\n * original message was: %q", + err, input, + ) + } +}