Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag that prints timestamps in skaffold logs. #5181

Merged
merged 9 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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