Commit 168e320
[cli] Add logsv2 command (#14656)
## Summary
Adds a new hidden `vercel logsv2` command that uses the newer
`/api/logs/request-logs` endpoint (same as the Vercel dashboard). This
provides project-scoped log querying with extensive filtering options,
designed to eventually replace the existing `logs` command.
## New Features
- **Project-scoped logs**: Query logs across all deployments in a
project (vs deployment-only in v1)
- **Rich filtering**: Level, source, status code, environment, time
range, request ID, and full-text search
- **Agent-native output**: JSON Lines format for easy piping to `jq` and
automation tools
- **Historical data**: Query past logs with `--since`/`--until` (vs
real-time only in v1)
## New Options
| Option | Type | Description |
|--------|------|-------------|
| `--project, -p` | string | Project ID or name (defaults to linked
project) |
| `--deployment, -d` | string | Filter to specific deployment ID or URL
|
| `--environment` | string | `production` or `preview` |
| `--level` | string[] | `error`, `warning`, `info`, `fatal`
(repeatable) |
| `--status-code` | string | HTTP status code filter (e.g., `500`,
`4xx`) |
| `--source` | string[] | `serverless`, `edge-function`,
`edge-middleware`, `static` |
| `--since` | string | Start time (ISO date or relative: `1h`, `30m`,
`2d`) |
| `--until` | string | End time (default: now) |
| `--limit, -n` | number | Maximum results (default: 100) |
| `--json, -j` | boolean | Output as JSON Lines for piping |
| `--query, -q` | string | Full-text search query |
| `--request-id` | string | Filter by request ID |
## Agent-Native Design
The command follows CLI best practices for automation:
- **JSON Lines output** (`--json`): Each log entry is a separate JSON
object on its own line
- **stdout/stderr separation**: Log data to stdout, status messages to
stderr
- **Clear exit codes**: 0 = success, 1 = error, 2 = help displayed
- **TTY detection**: Pretty output for terminals, plain for pipes
- **NO_COLOR support**: Respects color preferences
## Usage Examples
```bash
# View recent errors for linked project
vercel logsv2 --level error --since 1h
# Search logs with JSON output for jq processing
vercel logsv2 --json --query "timeout" | jq '.statusCode'
# Filter by deployment and status code
vercel logsv2 --deployment dpl_abc123 --status-code 500
# Production errors in the last day
vercel logsv2 --environment production --level error --since 1d
# Filter by specific request ID
vercel logsv2 --request-id req_xxxxx
```
## Comparison: logs vs logsv2
| Feature | `logs` (v1) | `logsv2` (new) |
|---------|-------------|----------------|
| Scope | Single deployment | Project-wide (+ optional deployment
filter) |
| Data access | Real-time streaming | Historical via pagination |
| Filtering | None (use jq) | level, source, status, environment,
request ID, search |
| Time range | "now" only | `--since` / `--until` |
| API | `/v1/.../runtime-logs` (streaming) | `/api/logs/request-logs`
(REST) |
| Timeout | 5 minutes auto-abort | None |
## Breaking Changes
None - this is a new hidden command. The existing `logs` command is
unchanged.
## Rollout Strategy
1. **Phase 1 (this PR)**: Hidden `vercel logsv2` command for testing
2. **Phase 2**: Feature flag to redirect `vercel logs` → `logsv2`
3. **Phase 3**: Promote to default, deprecate v1
## Test Plan
- [x] Unit tests for `logs-v2.ts` utility (18 tests)
- [x] Unit tests for `logsv2` command (34 tests)
- [x] Manual testing with linked project
- [x] Manual testing with `--project` flag
- [x] Verify JSON output pipes correctly to `jq`
- [ ] Test all filter combinations
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 3bf2458 commit 168e320
File tree
13 files changed
+1709
-0
lines changed- .changeset
- packages/cli
- src
- commands
- logsv2
- util
- telemetry
- commands/logsv2
- test
- fixtures/unit/commands
- git/connect/unlinked
- logsv2/linked-project/.vercel
- unit
- commands
- logsv2
- util
13 files changed
+1709
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
0 commit comments