Skip to content

Commit

Permalink
Add flag that prints timestamps in skaffold logs. (#5181)
Browse files Browse the repository at this point in the history
* Add a flag that prints timestamps in skaffold logs.

* Add flag definition.

* Run ./hack/generate-man.sh

* gofmt cmd/skaffold/app/cmd/cmd.go
  • Loading branch information
jtzwu authored Dec 23, 2020
1 parent a518ce7 commit 35214eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
forceColors bool
overwrite bool
interactive bool
timestamps bool
shutdownAPIServer func() error
)

Expand Down Expand Up @@ -76,7 +77,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
cmd.Root().SetOutput(out)

// Setup logs
if err := setUpLogs(err, v); err != nil {
if err := setUpLogs(err, v, timestamps); err != nil {
return err
}

Expand Down Expand Up @@ -182,6 +183,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
rootCmd.PersistentFlags().BoolVar(&forceColors, "force-colors", false, "Always print color codes (hidden)")
rootCmd.PersistentFlags().BoolVar(&interactive, "interactive", true, "Allow user prompts for more information")
rootCmd.PersistentFlags().BoolVar(&update.EnableCheck, "update-check", true, "Check for a more recent version of Skaffold")
rootCmd.PersistentFlags().BoolVar(&timestamps, "timestamps", false, "Print timestamps in logs.")
rootCmd.PersistentFlags().MarkHidden("force-colors")

setFlagsFromEnvVariables(rootCmd)
Expand Down Expand Up @@ -231,13 +233,16 @@ func FlagToEnvVarName(f *pflag.Flag) string {
return fmt.Sprintf("SKAFFOLD_%s", strings.Replace(strings.ToUpper(f.Name), "-", "_", -1))
}

func setUpLogs(stdErr io.Writer, level string) error {
func setUpLogs(stdErr io.Writer, level string, timestamp bool) error {
logrus.SetOutput(stdErr)
lvl, err := logrus.ParseLevel(level)
if err != nil {
return fmt.Errorf("parsing log level: %w", err)
}
logrus.SetLevel(lvl)
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: timestamp,
})
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Env vars:

* `SKAFFOLD_COLOR` (same as `--color`)
* `SKAFFOLD_INTERACTIVE` (same as `--interactive`)
* `SKAFFOLD_TIMESTAMPS` (same as `--timestamps`)
* `SKAFFOLD_UPDATE_CHECK` (same as `--update-check`)
* `SKAFFOLD_VERBOSITY` (same as `--verbosity`)

Expand Down Expand Up @@ -747,6 +748,7 @@ The following options can be passed to any command:
--color=34: Specify the default output color in ANSI escape codes
--interactive=true: Allow user prompts for more information
--timestamps=false: Print timestamps in logs.
--update-check=true: Check for a more recent version of Skaffold
-v, --verbosity='warning': Log level (debug, info, warn, error, fatal, panic)
Expand Down

0 comments on commit 35214eb

Please sign in to comment.