cli: Refactor the logger setup

This commit is contained in:
James Shubin
2024-03-22 01:21:04 -04:00
parent d2188609e4
commit 8cf7719476
3 changed files with 16 additions and 13 deletions

View File

@@ -31,6 +31,8 @@
package util
import (
"log"
"os"
"strings"
"github.com/purpleidea/mgmt/util/errwrap"
@@ -81,3 +83,16 @@ func SafeProgram(program string) string {
//}
return program
}
// LogSetup changes some of the core logger package settings.
func LogSetup(debug bool) {
// TODO: Move these log package initialization steps to the top main.go?
logFlags := log.LstdFlags
if debug {
logFlags = logFlags + log.Lshortfile
}
logFlags = logFlags - log.Ldate // remove the date for now
log.SetFlags(logFlags)
log.SetOutput(os.Stderr)
}