Skip to content

Conversation

@0xBigBoss
Copy link

@0xBigBoss 0xBigBoss commented Jan 5, 2026

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) format

Usage Examples

# Time-based filtering
tilt logs --since 5m
tilt logs api --since 1h

# Tail limiting
tilt logs --tail 100
tilt logs --tail 50 -f  # Last 50 lines, then stream all new

# JSON output
tilt logs --json

Implementation

  • 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"
  • LogStreamer tracks isFirstBatch to apply tail only to initial history in follow mode

Follows existing patterns from --level and --source flags (PR #6513).

Test plan

  • Unit tests for time-based filtering (TestLogFilterApplyWithSince)
  • Unit tests for tail limiting (TestLogFilterApplyWithTail)
  • Unit tests for JSON output (TestJSONPrinter*)
  • Integration tests for LogStreamer
  • go vet passes
  • go build succeeds
  • Manual testing with tilt logs --help

Closes #6652

@0xBigBoss 0xBigBoss force-pushed the feat/logs-since-tail-json-clean branch from fcbc0e8 to 0d668ef Compare January 5, 2026 23:19
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>
@0xBigBoss 0xBigBoss force-pushed the feat/logs-since-tail-json-clean branch from 0d668ef to acd5e01 Compare January 5, 2026 23:56
@0xBigBoss 0xBigBoss marked this pull request as ready for review January 6, 2026 13:30
Copy link
Member

@nicks nicks left a 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!

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"`)
Copy link
Member

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

source FilterSource
resources FilterResources
level logger.Level
since time.Duration
Copy link
Member

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)

0xBigBoss added a commit to 0xBigBoss/tilt that referenced this pull request Jan 10, 2026
…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>
0xBigBoss added a commit to 0xBigBoss/tilt that referenced this pull request Jan 10, 2026
…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>
@0xBigBoss 0xBigBoss force-pushed the feat/logs-since-tail-json-clean branch from 1bdf46e to 40489d5 Compare January 10, 2026 03:12
…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>
@0xBigBoss 0xBigBoss force-pushed the feat/logs-since-tail-json-clean branch from 40489d5 to bc61965 Compare January 10, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): enhance tilt logs with --since, --tail, and --json flags

2 participants