Skip to content

Commit 35214eb

Browse files
authored
Add flag that prints timestamps in skaffold logs. (#5181)
* Add a flag that prints timestamps in skaffold logs. * Add flag definition. * Run ./hack/generate-man.sh * gofmt cmd/skaffold/app/cmd/cmd.go
1 parent a518ce7 commit 35214eb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

cmd/skaffold/app/cmd/cmd.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var (
4545
forceColors bool
4646
overwrite bool
4747
interactive bool
48+
timestamps bool
4849
shutdownAPIServer func() error
4950
)
5051

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

7879
// Setup logs
79-
if err := setUpLogs(err, v); err != nil {
80+
if err := setUpLogs(err, v, timestamps); err != nil {
8081
return err
8182
}
8283

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

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

234-
func setUpLogs(stdErr io.Writer, level string) error {
236+
func setUpLogs(stdErr io.Writer, level string, timestamp bool) error {
235237
logrus.SetOutput(stdErr)
236238
lvl, err := logrus.ParseLevel(level)
237239
if err != nil {
238240
return fmt.Errorf("parsing log level: %w", err)
239241
}
240242
logrus.SetLevel(lvl)
243+
logrus.SetFormatter(&logrus.TextFormatter{
244+
FullTimestamp: timestamp,
245+
})
241246
return nil
242247
}
243248

docs/content/en/docs/references/cli/_index.md

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Env vars:
100100

101101
* `SKAFFOLD_COLOR` (same as `--color`)
102102
* `SKAFFOLD_INTERACTIVE` (same as `--interactive`)
103+
* `SKAFFOLD_TIMESTAMPS` (same as `--timestamps`)
103104
* `SKAFFOLD_UPDATE_CHECK` (same as `--update-check`)
104105
* `SKAFFOLD_VERBOSITY` (same as `--verbosity`)
105106

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

0 commit comments

Comments
 (0)