diff --git a/cmd/root.go b/cmd/root.go index fcab355..e27995e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,13 +31,15 @@ import ( type LogFormat enumflag.Flag const ( - TEXT LogFormat = iota - JSON + LoggingLogFmt LogFormat = iota + LoggingText + LoggingJson ) var LogFormatIds = map[LogFormat][]string{ - TEXT: {"text"}, - JSON: {"json"}, + LoggingLogFmt: {"logfmt"}, + LoggingText: {"text"}, + LoggingJson: {"json"}, } var ( @@ -79,7 +81,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file (default is $HOME/.pinned-package-updater.yaml OR ./.pinned-package-updater.yaml)") rootCmd.PersistentFlags().CountVarP(&logVerbosity, "verbose", "v", "verbose (-v, or -vv)") - rootCmd.PersistentFlags().VarP(enumflag.New(&logFormat, "logFormat", LogFormatIds, enumflag.EnumCaseInsensitive), "format", "", "The logging format to use [text, json]") + rootCmd.PersistentFlags().VarP(enumflag.New(&logFormat, "logFormat", LogFormatIds, enumflag.EnumCaseInsensitive), "format", "", "The logging format to use [logfmt, text, json]") // Cobra also supports local flags, which will only run // when this action is called directly. @@ -131,9 +133,14 @@ func initLogging() { } switch logFormat { - case TEXT: + case LoggingLogFmt: + log.SetFormatter(&log.TextFormatter{ + DisableColors: true, + FullTimestamp: true, + }) + case LoggingText: log.SetFormatter(&log.TextFormatter{}) - case JSON: + case LoggingJson: log.SetFormatter(&log.JSONFormatter{}) default: log.SetFormatter(&log.TextFormatter{})