Skip to content

feat(cli): add prisma dev logs and point the dev front door at it - #378

Closed
sneub wants to merge 7 commits into
mainfrom
feat/dev-logs
Closed

sneub wants to merge 7 commits into
mainfrom
feat/dev-logs

Conversation

@sneub

@sneub sneub commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Refs #253 (which dropped log from the family). Relitigates ADR-0050's "logs are a script" call. Needs sign-off from whoever owned the 2026-08-21 PM review before merge.

Summary

A console.log in a prisma dev service currently goes nowhere a user can find: dev deliberately doesn't stream service output, and reading it means writing a log() script or tail -f'ing a file under ~/.prisma-composer. This adds prisma dev logs [address] beside dev url / dev stop, and makes the dev front door say where the logs are.

  • prisma dev logs [address]: each service's last 100 lines, then exit. --tail <n> and --follow match prisma service logs. Log lines go to stdout, prefixed [address] unless one address is given. --json emits one output frame per line with data: { service, line }.
  • Front door: prints logs: prisma dev logs after the URLs, and adds a run-command remediation for agents.
  • devLogs operation on @prisma/composer/control. Like devUrl/devStop, it finds the app through current(), so it needs no entry module. log() stays unchanged.
  • Seam: an optional LocalTargetAttachment.readLogs({ tail }), backed by the compute emulator's existing non-follow GET /instances/<id>/logs. It's optional so an older app-side @prisma/composer-prisma-cloud fails with DEV.LOGS_UNSUPPORTED instead of following forever. This can happen because the CLI's Composer and the app's can be different versions.
  • New codes: DEV.NO_LOGS (the address is a database or bucket) and DEV.LOGS_UNSUPPORTED. Otherwise it reuses DEV.NOT_STARTED_HERE, DEV.ADDRESS_UNKNOWN and DEV.EMULATOR_UNREACHABLE.
  • ADR-0056, which amends ADR-0050 and ADR-0043. The guides, local-dev.md and the core-concepts skill are updated.

Testing performed

  • pnpm build && pnpm typecheck && pnpm lint && pnpm lint:deps: all pass.
  • bun test in @internal/cli (301 pass) and @internal/local-target. Real-emulator tests for readLogs in dev-emulators and the target's local-target-attach.test.ts.
  • @prisma/integration-tests: all pass. local-dev-detach gains a step that checks the front-door line in real prisma dev --json output, then reads the fixture's own console.log through devLogs: one service's tail, all services labelled, a followed stream, and DEV.NO_LOGS for the database.
  • Manual: a fresh create-prisma Next app with a console.log in a route handler. Its prisma dev logs app --tail 20 showed the handler's line. --follow picked up a new request live. Against the published 0.33.0 target, it gives DEV.LOGS_UNSUPPORTED.
  • Not passing locally, and unrelated: suites that spawn initdb (storage, auth, email, streams, prisma-cloud) fail on my machine because Homebrew's libpq has no postgres binary.

Checklist

  • All commits are signed off (git commit -s).
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • The PR title is a conventional commit.
  • Tests are updated.

Notes for the reviewer

  • Non-follow is the default, matching prisma service logs, and a command that ends by itself suits agents. Without --follow, lines are grouped by service in address order rather than interleaved. The per-service logs have no timestamps, so any interleaving would be invented.
  • Deferred: prisma dev --logs (inline streaming). The engine buffers command output while the converge child owns the terminal, so it needs its own design. ADR-0056 says so.
  • prisma-cli side: draft Mount Composer's prisma dev logs prisma-cli#369 mounts dev logs; it goes green once this publishes and the pins bump.

@prisma-gizmo

prisma-gizmo Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

✅ Gizmo reviewed 96b22fa — posted 1 inline comment(s) this pass.

Open findings: 🟡 3 minor

Change walkthrough

This PR adds prisma dev logs [address] — each service's last 100 lines, then exit; --tail and --follow copy prisma service logs — and makes the dev front door end with a logs: prisma dev logs line plus a run-command remediation for agents. It relitigates ADR-0050's "logs are a script" call, recorded in new ADR-0056, which amends ADR-0050 and ADR-0043.

Command family and operations. The family gains a dev-logs command wired through family.ts alongside dev url / dev stop, backed by a new devLogs operation exported from @prisma/composer/control. Like its siblings it finds the app through the current() seam, so it needs no entry module; the executor reuses DEV.NOT_STARTED_HERE, DEV.ADDRESS_UNKNOWN, DEV.EMULATOR_UNREACHABLE, DEV.NOT_RUNNING and DEV.EMULATOR_FAILED, and adds DEV.NO_LOGS (a database/bucket address) and DEV.LOGS_UNSUPPORTED (an older app-side target without readLogs). Non-follow reads happen before the Result is returned, so read failures are structured errors rather than throws out of the stream; an aborted read ends with the lines read so far.

Seam. LocalTargetAttachment gains an optional readLogs({ tail }), implemented by the Prisma Cloud target over the compute emulator's non-follow GET /instances/<id>/logs, with tailing done target-side and lost instances reading as empty. Optionality is the version-skew escape hatch: an older @prisma/composer-prisma-cloud fails with DEV.LOGS_UNSUPPORTED instead of following forever. ADR-0056 puts this route on the cross-version backward-compat list, like the instance-list routes.

Incidental data-lines work in the delta. dev stop, dev url and emulator list piped output now flows through a shared dataLine() helper that escapes backslash/tab/newline/carriage-return within fields, with the contract (fields appended only at the end) documented in running-locally.md and pinned by a new command-inventory test. converge.ts redirects a piped run's child stdout to stderr so the pipe carries only the parent's data lines.

Docs and tests. local-dev.md, the ADR index, the guides, and the core-concepts skill are updated consistently with the implementation (labelling, grouping rationale, failure-code table). Coverage spans unit tests over the operations double, executor-level tests for every failure code, real-emulator tests for readLogs, command-family tests, and a new local-dev-detach integration step reading a fixture's own console.log through devLogs, including a followed stream.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 7dbd5752-d660-42ad-af22-7cd047c36af7
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: 🟡 2 minor · trace

Comment on lines +242 to +255
if (address !== undefined && services.length === 0) {
const { kind } = await locateRecorded(current, address);
throw new CliStructuredError(
'DEV.NO_LOGS',
`"${address}" is a ${kind}, and only services have logs.`,
{
why: `A service's logs are what its process writes to stdout and stderr; a ${kind} runs none of your code.`,
fix: 'Pass the address of a service, or no address for every service.',
meta: { address, kind },
},
);
}
const [first] = services;
if (first === undefined) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · error-handling — DEV.NO_LOGS can be raised for a service address when the emulator has lost the instance, with a contradictory message

In logSources, services comes from attachment.endpoints(), which reads the compute emulator's instance registry. When the address names a recorded service whose instance the emulator no longer has (the 'missing' condition that ADR/local-dev.md handles as "a node its emulator lost… prisma dev creates it again"), services.length === 0 and the operation throws DEV.NO_LOGS with locateRecorded's kind — producing "gateway" is a service, and only services have logs., a self-contradictory message a script cannot branch on correctly. devUrl handles the identical state as DEV.NOT_RUNNING (see notRunning in this file). The emulator-not-running case is checked afterwards and never reached for such an address. Fix: when locateRecorded(current, address) reports a node whose condition is not present (or kind is service), raise DEV.NOT_RUNNING (or an emulator-specific code) instead of DEV.NO_LOGS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 05cd866, with one correction to the premise. endpoints() on the Prisma Cloud attachment lists services from the directory's record (nodeInstancesOf → appNodes → readRecord), not from the emulator's registry. So a service the emulator lost is still listed, and it reads as an empty log rather than as DEV.NO_LOGS. Core still shouldn't rely on how a target builds that list, and the ordering point stands: an address whose emulator was down hit NO_LOGS before the reachability check. An unlisted address is now checked first. Emulator down gives DEV.EMULATOR_UNREACHABLE, a node its emulator lost gives DEV.NOT_RUNNING (via the existing notRunning, same as devUrl), and only then DEV.NO_LOGS. Tested in dev-current.test.ts.

Comment on lines +277 to +285
sources: readonly LogSource[],
input: DevLogsInput,
tail: number,
): Promise<LogLine[]> {
const lines: LogLine[] = [];
for (const { attachment, services } of sources) {
const { readLogs } = attachment;
if (readLogs === undefined) throw logsUnsupported();
const wanted = new Set(services);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · error-handling — A non-follow read interrupted by Ctrl-C surfaces as DEV.EMULATOR_FAILED rather than a settled interrupt

readLines awaits every source's readLogs before executeDevLogs returns ok, which is the documented reason failures surface as results. But each call is wrapped in fromTarget, which converts any non-structured error — including an AbortError from input.signal firing mid-read, e.g. the CLI's own Ctrl-C while a slow read is in flight — into DEV.EMULATOR_FAILED. The command would then return a failure for a run the user deliberately interrupted. Low impact since the engine settles interrupted runs from its own signal record, but wrapping an abort as an emulator failure misnames the cause; consider rethrowing when input.signal?.aborted before calling toStructured.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in 05cd866. readLines no longer goes through fromTarget. When readLogs rejects and input.signal has aborted, it stops with the lines read so far and returns ok, so the host settles the interrupt from its own signal record. Any other rejection is still DEV.EMULATOR_FAILED. Both cases are tested in dev-current.test.ts.

sneub added a commit that referenced this pull request Oct 23, 2026
…eat an aborted read as an interrupt

Review feedback on #378:

- devLogs inferred "not a service" from the attachment not listing an
  address. The Prisma Cloud attachment lists services from the
  directory's record, so a lost service is still listed, but core should
  not rely on that, and an address whose emulator is down reached
  DEV.NO_LOGS before the reachability check. Now an unlisted address is
  checked first: emulator down -> DEV.EMULATOR_UNREACHABLE, node lost ->
  DEV.NOT_RUNNING, and only then DEV.NO_LOGS.
- A non-follow read rejected because the caller's signal aborted (Ctrl-C)
  was wrapped as DEV.EMULATOR_FAILED. It now ends with the lines read so
  far and leaves settling the interrupt to the host.

Signed-off-by: Shane Neubauer <[email protected]>

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: none · trace

Still open from previous reviews: 🟡 2 minor

sneub added 7 commits October 23, 2026 19:18
The local-target attachment could only follow logs, so a caller wanting
the last N lines and an exit had no way to know when the backlog ended.
The compute emulator already serves a non-follow GET of an instance's
log; the client gains readLogs() over it, and the Prisma Cloud
attachment gains readLogs({ tail }), which reads each service's log and
keeps its last lines.

readLogs is optional on LocalTargetAttachment so a target from before it
existed still loads; core refuses a non-follow read when it is absent
rather than silently following forever.

Signed-off-by: Shane Neubauer <[email protected]>
devLogs reads the logs of the app `prisma dev` last ran from a
directory, through the same current() record dev url and dev stop use,
so it needs no entry module. The existing log() operation takes an
entry and only follows, which makes it the wrong base for a command
that sits beside dev url/dev stop.

By default it returns each service's last 100 lines (the default
`prisma service logs` uses for a deployed service) and ends; follow:
true streams new lines until the signal aborts, through the same merge
log() uses. Failures reuse dev url's codes (DEV.NOT_STARTED_HERE,
DEV.ADDRESS_UNKNOWN, DEV.EMULATOR_UNREACHABLE) and add DEV.NO_LOGS for
an address that is not a service and DEV.LOGS_UNSUPPORTED for a target
without readLogs. A crash-looping service is read, not refused: its
log is exactly what the user needs.

The operations double gains devLogs so hosts can test the command.

Signed-off-by: Shane Neubauer <[email protected]>
`dev logs [address]` prints the services' log lines on stdout (labelled
[address] unless one address was named), everything else on stderr,
and each line as an output frame with data.service under --json. It
takes --tail and --follow like `prisma service logs`, so the local and
deployed log commands read the same.

`prisma dev` prints `logs: prisma dev logs` after the URLs, plus a
run-command remediation for agents, because it deliberately does not
stream service output itself (9cb1288) and nothing told users where
that output went.

Signed-off-by: Shane Neubauer <[email protected]>
ADR-0056 amends ADR-0050 (logs were script-only because their place in
the command tree was undecided) and ADR-0043 (a seventh control
operation): local logs live at `prisma dev logs`, beside dev url and dev
stop, leaving `prisma service logs` to mean deployed services.

The running-locally guide's Logs section leads with the command and
keeps the operation for code; getting-started, deploying, local-dev.md
and the core-concepts skill stop telling users that logs need a script.

Signed-off-by: Shane Neubauer <[email protected]>
The detach proof now checks the front door's `logs: prisma dev logs`
line in the real `prisma dev --json` output, then reads the fixture's
own console.log output through devLogs: one service's tail, every
service's lines labelled, a followed stream that starts with the tail,
and DEV.NO_LOGS for the database's address. This is the real-emulator
coverage the prisma CLI's e2e exclusion for `dev logs` points at.

Signed-off-by: Shane Neubauer <[email protected]>
…eat an aborted read as an interrupt

Review feedback on #378:

- devLogs inferred "not a service" from the attachment not listing an
  address. The Prisma Cloud attachment lists services from the
  directory's record, so a lost service is still listed, but core should
  not rely on that, and an address whose emulator is down reached
  DEV.NO_LOGS before the reachability check. Now an unlisted address is
  checked first: emulator down -> DEV.EMULATOR_UNREACHABLE, node lost ->
  DEV.NOT_RUNNING, and only then DEV.NO_LOGS.
- A non-follow read rejected because the caller's signal aborted (Ctrl-C)
  was wrapped as DEV.EMULATOR_FAILED. It now ends with the lines read so
  far and leaves settling the interrupt to the host.

Signed-off-by: Shane Neubauer <[email protected]>
main added command-stdout.test.ts, which inventories every command file.
dev logs prints its data lines through output events, so it passes the
two stdout checks; it only needed adding to the inventory.

Signed-off-by: Shane Neubauer <[email protected]>
@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@prisma/composer@378
npm i https://pkg.pr.new/@prisma/composer-cli@378
npm i https://pkg.pr.new/@prisma/composer-prisma-cloud@378

commit: 96b22fa

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: 🟡 1 minor · trace

Still open from previous reviews: 🟡 2 minor

test('reads every command source', () => {
expect(sources.map((source) => source.name).sort()).toEqual([
'deploy.ts',
'dev-logs.ts',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · consistency — Core CLI test reaches into packages/9-public by relative path, inverting the package layering

The inventory test in command-stdout.test.ts:26 asserts the exact file set of two directories — its own ../commands, and packages/9-public/composer-cli/src/family, reached by a hard-coded six-level relative path (lines 8-9). That makes the only file under packages/0-framework to reference 9-public (grep-verified), inverting the repo's layering: the innermost framework package's unit tests now fail whenever the outermost public package adds, renames or moves any .ts file in src/family, and a checkout that trims 9-public breaks @internal/cli's tests through no change of its own. The public package's half of the contract already has a natural home — packages/9-public/composer-cli/test/emulator-list.test.ts in this same PR asserts the mounted command keys.

Recommended fix

Keep this test scoped to its own package's ../commands directory, and assert the data-line contract for emulator-list.ts in packages/9-public/composer-cli/test/ against that package's own src/family files, so each layer's tests depend only on its own tree.

@sneub

sneub commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing without merging for now. We're pausing this and will come back to it later. The branch feat/dev-logs is kept.

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.

1 participant