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

logtail: add --timestamps flag #1254

Merged
merged 2 commits into from
Jul 26, 2024
Merged
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
8 changes: 8 additions & 0 deletions pkg/commands/logtail/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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.
Expand Down
Loading