-
Notifications
You must be signed in to change notification settings - Fork 370
feat(cli): add --since, --tail, --json flags to tilt logs #6656
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
base: master
Are you sure you want to change the base?
feat(cli): add --since, --tail, --json flags to tilt logs #6656
Conversation
fcbc0e8 to
0d668ef
Compare
Implements tilt-dev#6652 - adds filtering and JSON output capabilities to tilt logs: - --since: Filter logs by time (e.g., "5m", "1h", "30s") - --tail: Limit output to last N lines (applies only to initial history when combined with -f/--follow) - --json: Output logs as JSON Lines (JSONL) format - --json-fields: Configure JSON output fields ("minimal", "full", or comma-separated field list) Implementation details: - Extends LogFilter with Since/Tail fields and time-based filtering - Adds JSONPrinter for structured JSONL output with configurable fields - Uses pointer types in JSONLogLine to distinguish "not included" from "empty value" for --json-fields=full - LogStreamer tracks isFirstBatch to apply tail only to initial history - Validates --since (positive duration), --tail (>= -1), and --json-fields (rejects unknown field names) Closes tilt-dev#6652 Signed-off-by: Big Boss <bigboss@metalrodeo.xyz>
0d668ef to
acd5e01
Compare
nicks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat! thanks for doing this!
internal/cli/flags.go
Outdated
| cmd.Flags().StringVar(&logSinceFlag, "since", "", `Only show logs since duration ago (e.g., "5m", "1h", "30s")`) | ||
| cmd.Flags().IntVar(&logTailFlag, "tail", -1, `Number of lines to show from the end of logs (-1 for all)`) | ||
| cmd.Flags().BoolVar(&logJSONFlag, "json", false, `Output logs in JSON Lines format`) | ||
| cmd.Flags().StringVar(&logJSONFieldsFlag, "json-fields", "", `Fields to include in JSON output. Presets: "minimal" (default), "full". Or comma-separated: "time,resource,level,message"`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove this flag?
we try to follow a lot of the conventions of the kubectl and docker cli. this feels a bit too "bespoke." would rather we just expose a --json flag and people can filter the json with jq, which is a much richer interface for selecting fields and filtering
internal/hud/log_filter.go
Outdated
| source FilterSource | ||
| resources FilterResources | ||
| level logger.Level | ||
| since time.Duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's model this internally as a timestamp, not a duration. We can still accept a duration on the cli, but we should convert it to a timestamp at the cli layer.
(the problem with modelling it as a duration, as you discovered, is that it means that the behavior of the functions changes depending on when you call them. and you need hacks like MatchesWithTime)
…p for since Address PR tilt-dev#6656 review comments: 1. Remove --json-fields flag - users should use jq for field filtering, following kubectl/docker CLI conventions 2. Model --since as timestamp internally instead of duration: - FilterSince changed from time.Duration to time.Time - Duration-to-timestamp conversion happens at CLI layer - Eliminates time-dependent behavior and MatchesWithTime hack - Simplifies Apply methods (no longer need 'now' parameter) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…p for since Address PR tilt-dev#6656 review comments: 1. Remove --json-fields flag - users should use jq for field filtering, following kubectl/docker CLI conventions 2. Model --since as timestamp internally instead of duration: - FilterSince changed from time.Duration to time.Time - Duration-to-timestamp conversion happens at CLI layer - Eliminates time-dependent behavior and MatchesWithTime hack - Simplifies Apply methods (no longer need 'now' parameter) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Big Boss <bigboss@metalrodeo.xyz>
1bdf46e to
40489d5
Compare
…p for since Address PR tilt-dev#6656 review comments: 1. Remove --json-fields flag - users should use jq for field filtering, following kubectl/docker CLI conventions 2. Model --since as timestamp internally instead of duration: - FilterSince changed from time.Duration to time.Time - Duration-to-timestamp conversion happens at CLI layer - Eliminates time-dependent behavior and MatchesWithTime hack - Simplifies Apply methods (no longer need 'now' parameter) Signed-off-by: Big Boss <bigboss@metalrodeo.xyz>
40489d5 to
bc61965
Compare
Summary
Implements #6652 - adds filtering and JSON output capabilities to
tilt logs:--since: Filter logs by time (e.g.,--since 5m,--since 1h)--tail: Limit output to last N lines (applies only to initial history when combined with-f)--json: Output logs as JSON Lines (JSONL) formatUsage Examples
Implementation
LogFilterwithSince/Tailfields and time-based filteringJSONPrinterfor structured JSONL output with configurable fieldsJSONLogLineto distinguish "not included" from "empty value"LogStreamertracksisFirstBatchto apply tail only to initial history in follow modeFollows existing patterns from
--leveland--sourceflags (PR #6513).Test plan
TestLogFilterApplyWithSince)TestLogFilterApplyWithTail)TestJSONPrinter*)go vetpassesgo buildsucceedstilt logs --helpCloses #6652