Skip to content

feat(logs): summarize entries by service and level - #491

Merged
jongio merged 4 commits into
mainfrom
idea/logs-summary
Jul 28, 2026
Merged

feat(logs): summarize entries by service and level#491
jongio merged 4 commits into
mainfrom
idea/logs-summary

Conversation

@jongio

@jongio jongio commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Closes #488

Summary

  • add azd app logs --summary
  • count filtered log entries by service and level
  • return a single JSON summary when --output json is used
  • include the time range when entries have timestamps

Verification

  • go test .\src\cmd\app\commands -run "Test(BuildLogSummary|DisplayLogSummary|ValidateLogsOptions|LogsCommandStructure)"
  • mage test
  • mage build

Closes #488

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jongio jongio added the idea Feature idea from the idea pipeline label Jul 11, 2026
@jongio jongio self-assigned this Jul 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Website Preview

Your PR preview is ready!

📎 Preview URL: https://jongio.github.io/azd-app/pr/491/

This preview will be automatically cleaned up when the PR is closed.

github-actions Bot added a commit that referenced this pull request Jul 11, 2026

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review — Approve ✅

Clean, well-scoped addition of azd app logs --summary. The summary builders are pure and unit-tested, level mapping is consistent with the existing logLevelToString, and the --summary/--follow conflict is validated. No Critical, High, or Medium issues found.

What was verified

  • normalizeLogSummaryLevel return values (info/warn/error/debug/unknown) match the switch cases in buildLogSummary against the real constants (logLevelWarn="warn", statusError="error", logLevelDebug="debug"). ✔
  • Timestamp min/max tracking correctly copies the loop value and yields nil pointers (omitted in JSON, skipped in text) when no entry has a timestamp. ✔
  • Summary short-circuit is placed after the output writer is set up, so --summary --file <path> and --output json both work. ✔
  • Tests cover both builders, text + JSON rendering, flag registration, and the follow conflict.

Non-blocking observations (Low / nitpick)

  • logLevelToString returns "info" for unrecognized service.LogLevel values (its default), so the Unknown column/field is effectively dead for the non-context (buildLogSummaryFromEntries) path — only the context-log path (raw string levels) can ever populate Unknown. Consider mapping unknown enum values to "unknown" here if you want the column to be meaningful for local logs, otherwise it's harmlessly always zero.
  • displayLogSummary swallows the JSON encode error by writing to os.Stderr and returning nothing; the caller in execute() also discards it. Fine in practice (encoding this struct won't fail), but returning the error would be more consistent with the surrounding code.
  • Service column is %-20s; service names longer than 20 chars will misalign the text table. Purely cosmetic.
  • Minor test-style nit: TestValidateLogsOptions special-cases if tt.name == "summary with follow" to set fields rather than driving them from table columns — works, just slightly asymmetric with the rest of the table.

Nice work — approving.

jongio and others added 2 commits July 28, 2026 00:12
errcheck flagged the unchecked fmt.Fprintf and fmt.Fprintln return values in
displayLogSummary. Discard them explicitly with the same _, _ = form the rest
of the commands package already uses for io.Writer output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jul 28, 2026

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review (re-review @ d93bc02) — Approve ✅

Re-reviewed after new commits landed since my previous approval at 9a51cf8. Two additions:

  1. Merge of origin/main into the branch — verified via git diff origin/main...HEAD: the net feature delta is unchanged (logs.go +14, logs_filtering.go +4, logs_summary.go +159). No behavioral impact on the summary feature from the merge.
  2. fix(logs): check writer errors in log summary output (d93bc02) — prepends _, _ = to the fmt.Fprintf/Fprintln calls in the text branch of displayLogSummary to explicitly discard writer return values (satisfies errcheck).

The core logic I validated in my prior pass (level normalization vs the real constants, nil-timestamp handling, JSON/text rendering, the --summary/--follow guard, and test coverage) is unchanged and still correct.

No Critical, High, or Medium issues found — approving.

Non-blocking observations (Low / nitpick)

  • The commit is titled "check writer errors" but the change actually discards them (_, _ =) rather than checking/propagating. Cosmetic naming mismatch; behavior is fine for stdout/buffer writers.
  • The JSON branch is left as-is (still logs an encode error to os.Stderr and returns), so writer-error handling is now slightly asymmetric between the JSON and text paths. Harmless in practice.
  • Prior nits still stand and remain non-blocking: Unknown column is effectively always zero for the local-log path (logLevelToString defaults unknown enums to "info"), and the %-20s service column can misalign for names >20 chars.

Nice iteration — approving.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.50515% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.23%. Comparing base (4e6c9c3) to head (373c99e).

Files with missing lines Patch % Lines
cli/src/cmd/app/commands/logs_summary.go 88.37% 7 Missing and 3 partials ⚠️
cli/src/cmd/app/commands/logs.go 33.33% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #491      +/-   ##
==========================================
+ Coverage   62.14%   62.23%   +0.08%     
==========================================
  Files         225      226       +1     
  Lines       29762    29859      +97     
==========================================
+ Hits        18497    18583      +86     
- Misses       9996    10002       +6     
- Partials     1269     1274       +5     
Flag Coverage Δ
unittests 62.23% <83.50%> (+0.08%) ⬆️

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

Files with missing lines Coverage Δ
cli/src/cmd/app/commands/logs_filtering.go 71.68% <100.00%> (+4.86%) ⬆️
cli/src/cmd/app/commands/logs.go 64.41% <33.33%> (-0.72%) ⬇️
cli/src/cmd/app/commands/logs_summary.go 88.37% <88.37%> (ø)

... and 2 files with indirect coverage changes

🚀 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.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🚀 Test This PR

A preview build (0.20.0-pr491) is ready for testing!

🌐 Website Preview

Live Preview: https://jongio.github.io/azd-app/pr/491/

One-Line Install (Recommended)

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-app/main/cli/scripts/install-pr.ps1) } -PrNumber 491 -Version 0.20.0-pr491"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-app/main/cli/scripts/install-pr.sh | bash -s 491 0.20.0-pr491

Uninstall

When you're done testing:

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-app/main/cli/scripts/uninstall-pr.ps1) } -PrNumber 491"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-app/main/cli/scripts/uninstall-pr.sh | bash -s 491

Build Info:

What to Test:
Please review the PR description and test the changes described there.

Resolves logs test conflicts by keeping the min-level, no-timestamps, and summary test cases from both sides.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jul 28, 2026

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review (re-review @ 373c99e) — Approve ✅

Re-reviewed after a new commit landed since my previous approval at d93bc02:

  • chore: merge main into idea/logs-summary (373c99e) — merges the latest origin/main into the branch.

Verification of the merge:

  • The PR's net diff vs the merge base (4e6c9c3) is unchanged — still exactly the summary feature across the same 5 files (logs.go +14, logs_command_test.go +6/-1, logs_filtering.go +4, logs_summary.go +159, logs_summary_test.go +102).
  • logs_summary.go at this head resolves to the same blob (bdda7315) I approved at d93bc02 — byte-identical.
  • No conflict markers in any feature file; the merge integrated cleanly.
  • Unrelated features that arrived on main (--min-level, --no-timestamps) are present equally in base and head, so they net out of this PR and are not part of its contribution.

The summary logic I validated in prior passes (level normalization vs the real constants, nil-timestamp handling, JSON/text rendering, the --summary/--follow guard, and test coverage) is unchanged and still correct.

No Critical, High, or Medium issues found — approving.

Non-blocking observations (Low / nitpick — carried from prior reviews, still applicable)

  • Unknown column is effectively always zero on the local-log path, since logLevelToString maps unknown enum values to "info".
  • The %-20s service column can misalign for service names longer than 20 characters (cosmetic).
  • Writer-error handling is asymmetric: the text path discards Fprintf returns (_, _ =) while the JSON path logs an encode error to stderr. Harmless in practice.

Nice work — approving.

@jongio
jongio merged commit b5b6a4b into main Jul 28, 2026
20 checks passed
github-actions Bot added a commit that referenced this pull request Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

idea Feature idea from the idea pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Summarize service logs by level and service

2 participants