Skip to content

feat: add func logs command to stream function logs#3669

Open
Itx-Psycho0 wants to merge 2 commits intoknative:mainfrom
Itx-Psycho0:feature/3521-add-func-logs-command
Open

feat: add func logs command to stream function logs#3669
Itx-Psycho0 wants to merge 2 commits intoknative:mainfrom
Itx-Psycho0:feature/3521-add-func-logs-command

Conversation

@Itx-Psycho0
Copy link
Copy Markdown

This PR implements the func logs command requested in issue #3521.

The command provides a simple way to stream logs from deployed functions without needing to know the underlying service name or pod details.

Usage examples:

  • Stream logs from current directory: func logs
  • Stream logs by name: func logs --name my-function
  • Filter by time: func logs --since 5m
  • Custom namespace: func logs --namespace my-ns

Implementation details:

  • Uses the existing GetKServiceLogs functionality from the knative package
  • Supports graceful shutdown with Ctrl+C
  • Includes comprehensive tests
  • All tests and linting checks pass

The command is added to the Development Commands group alongside run, invoke, and build commands.

Fixes #3521

This adds a new 'func logs' command that streams logs from deployed functions,
abstracting away the underlying service name and pod details.

Features:
- Stream logs for function in current directory
- Stream logs by function name with --name flag
- Filter logs by time with --since flag (e.g., 5m, 1h)
- Support for custom namespace with --namespace flag
- Graceful handling of Ctrl+C to stop log streaming

The command uses the existing GetKServiceLogs functionality from the knative
package, providing a user-friendly CLI interface for developers.

Fixes knative#3521
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 7, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Itx-Psycho0
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 7, 2026 12:49
@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 7, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 7, 2026

Hi @Itx-Psycho0. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Itx-Psycho0
Copy link
Copy Markdown
Author

Hi @lkingland @jrangelramos,

I've implemented the func logs command as discussed in this issue. The implementation uses the Kubernetes logs API approach as suggested by @srikaryt2.

The command provides a clean interface for streaming function logs without requiring users to know service names or pod details. It supports filtering by time and works with both local functions and functions specified by name.

All tests pass and the implementation follows the existing command patterns in the codebase.

Looking forward to your feedback.

Thanks!

@matejvasek matejvasek requested review from gauron99 and lkingland and removed request for dsimansk and jrangelramos May 7, 2026 22:32
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 29.31034% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.66%. Comparing base (33a9d85) to head (c0bf31f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/logs.go 28.69% 80 Missing and 2 partials ⚠️

❗ There is a different number of reports uploaded between BASE (33a9d85) and HEAD (c0bf31f). Click for more details.

HEAD has 11 uploads less than BASE
Flag BASE (33a9d85) HEAD (c0bf31f)
e2e 3 2
unit windows-latest 1 0
e2e-config-ci 1 0
e2e springboot 1 0
e2e node 1 0
e2e typescript 1 0
e2e rust 1 0
integration 1 0
e2e quarkus 1 0
e2e python 1 0
e2e go 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3669      +/-   ##
==========================================
- Coverage   56.61%   47.66%   -8.95%     
==========================================
  Files         181      181              
  Lines       20853    20963     +110     
==========================================
- Hits        11806     9993    -1813     
- Misses       7833    10062    +2229     
+ Partials     1214      908     -306     
Flag Coverage Δ
e2e 22.71% <29.31%> (-13.55%) ⬇️
e2e go ?
e2e node ?
e2e python ?
e2e quarkus ?
e2e rust ?
e2e springboot ?
e2e typescript ?
e2e-config-ci ?
integration ?
unit macos-14 44.58% <31.52%> (-0.08%) ⬇️
unit macos-latest 44.58% <31.52%> (-0.08%) ⬇️
unit ubuntu-24.04-arm 44.82% <29.31%> (-0.09%) ⬇️
unit ubuntu-latest 45.43% <31.52%> (-0.08%) ⬇️
unit windows-latest ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add func logs command

1 participant