From ad4b939e13d877410b1d8fd49f1abbd2279a8840 Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Fri, 26 Jul 2024 15:49:27 -0400 Subject: [PATCH] logtail: add --timestamps flag (#1254) --- pkg/commands/logtail/root.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/commands/logtail/root.go b/pkg/commands/logtail/root.go index 63a40f32f..e3adf7db0 100644 --- a/pkg/commands/logtail/root.go +++ b/pkg/commands/logtail/root.go @@ -63,6 +63,7 @@ func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand { c.CmdClause.Flag("sort-buffer", "Duration of sort buffer for received logs").Default("1s").DurationVar(&c.cfg.sortBuffer) c.CmdClause.Flag("search-padding", "Time beyond from/to to consider in searches").Default("2s").DurationVar(&c.cfg.searchPadding) c.CmdClause.Flag("stream", "Output: stdout, stderr, both (default)").StringVar(&c.cfg.stream) + c.CmdClause.Flag("timestamps", "Print timestamps with logs").BoolVar(&c.cfg.printTimestamps) return &c } @@ -446,6 +447,10 @@ func (c *RootCommand) printLogs(out io.Writer, logs []Log) { filtered := filterStream(c.cfg.stream, logs) for _, l := range filtered { + if c.cfg.printTimestamps { + fmt.Fprint(out, l.RequestStartFromRaw().UTC().Format(time.RFC3339)) + fmt.Fprint(out, " | ") + } fmt.Fprintln(out, l.String()) } } @@ -486,6 +491,9 @@ type ( // to is when to get logs until. to int64 + // printTimestamps is whether to print timestamps with logs. + printTimestamps bool + // sortBuffer is how long to buffer logs from when the cli // receives them to when the cli prints them. It will sort // by RequestID for that buffer period.