feat(logs): add --tail flag for real-time log streaming#424
Draft
feat(logs): add --tail flag for real-time log streaming#424
Conversation
Contributor
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.0.45-pr.424.8513dafPrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.0.45-pr.424.8513daf"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.0.45-pr.424.8513daf"
}
}
Preview published to npm registry — try new features instantly! |
- Add streamFunctionLogs() async generator in core layer using ky with timeout:false, SSE line parsing, and malformed JSON resilience - Export FunctionLogEntry type and add StreamLogFilters interface - Register --tail (-f) and --json flags on the logs command - Implement tailAction with multi-function support (one SSE connection per function), SIGINT cleanup, and stream shutdown policy - Validate incompatible flag combinations (--tail with --since/--until/ --limit/--order) - JSON mode outputs NDJSON with source field for piping Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Core unit tests: SSE parsing, heartbeat filtering, malformed JSON, null body, abort signal, level filter passthrough - Integration tests: streaming output, --json with source field, multi-function tailing, flag validation, heartbeat ignore, stream error handling - Add mockFunctionLogsStream helper to TestAPIServer Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Description
Adds a
--tailflag (-f) to thelogscommand that streams real-time function logs via Server-Sent Events (SSE). The newstreamFunctionLogsasync generator in the core layer connects to a streaming endpoint, parses SSEdata:lines into typed log entries, and handles heartbeat comments and graceful SIGINT shutdown. Multiple functions can be tailed concurrently usingPromise.allSettled.Related Issue
None
Type of Change
Changes Made
packages/cli/src/cli/commands/project/logs.ts— Added--tail/-foption to thelogscommand; addedtailAction()that builds anAbortController, streams one or more functions concurrently, and prints entries (plain or--json) to stdout; validates that--tailis mutually exclusive with--since,--until,--limit, and--order; updated command descriptionpackages/cli/src/core/resources/function/api.ts— AddedstreamFunctionLogsasync generator that callsgetAppClient().get()withtimeout: false, reads theReadableStreambody incrementally, and yields validatedFunctionLogEntryobjects parsed from SSEdata:lines; skips heartbeat comments (:lines) and malformed JSON silentlypackages/cli/src/core/resources/function/schema.ts— ExportedFunctionLogEntrySchemaandFunctionLogEntrytype; addedStreamLogFiltersinterface with optionallevelfilterpackages/cli/tests/cli/logs.spec.ts— Added 9 new integration tests covering incompatible-flag validation, single/multi-function streaming,--jsonoutput, error propagation, stream-ended message, and SSE heartbeat filteringpackages/cli/tests/cli/testkit/TestAPIServer.ts— AddedmockFunctionLogsStream()andmockFunctionLogsStreamError()helpers for SSE stream test routespackages/cli/tests/core/stream-function-logs.spec.ts— New unit test file covering SSE parsing, heartbeat skipping, malformed-JSON resilience, null-body error, and level filter query paramTesting
npm test)Checklist
docs/(AGENTS.md) if I made architectural changesAdditional Notes
The
streamFunctionLogsfunction deliberately avoidsresponse.json()/response.text()(which buffer the full body) and instead reads fromresponse.bodyincrementally as aReadableStream. This is noted in an inline comment to prevent future regressions. The--tailflag intentionally mirrors the familiartail -f/docker logs -fUX pattern.🤖 Generated by Claude | 2026-03-17 00:00 UTC