-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add awf logs stats and awf logs summary commands
#118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add built-in log aggregation and summary generation to reduce complexity of parsing firewall logs in GitHub Actions workflows. New commands: - `awf logs stats` - Show aggregated statistics (default: pretty format) - `awf logs summary` - Generate summary report (default: markdown format) Both commands support --format json|markdown|pretty for flexible output. Example GitHub Actions usage: awf logs summary >> $GITHUB_STEP_SUMMARY This replaces 150+ lines of custom JavaScript log parsing with a single command. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Test Coverage Report
Coverage ThresholdsThe project has the following coverage thresholds configured:
Coverage report generated by `npm run test:coverage` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds two new CLI commands (awf logs stats and awf logs summary) that aggregate and display firewall log statistics in multiple formats. The commands are specifically designed to simplify log analysis in GitHub Actions workflows, replacing the need for custom parsing scripts.
Key changes:
- New log aggregation module that computes statistics from parsed Squid log entries
- Flexible output formatters supporting JSON, Markdown, and pretty-printed terminal formats
- Two command interfaces:
stats(terminal-focused, defaults to pretty) andsummary(GitHub Actions-focused, defaults to markdown)
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
src/logs/log-aggregator.ts |
Implements log loading and aggregation logic for computing statistics across all log entries |
src/logs/log-aggregator.test.ts |
Comprehensive test suite for aggregation logic, including edge cases for empty logs and missing domains |
src/logs/stats-formatter.ts |
Formatters for JSON, Markdown, and pretty-printed terminal output with color support |
src/logs/stats-formatter.test.ts |
Tests for all three output formatters, including singular/plural handling and domain filtering |
src/logs/index.ts |
Exports new aggregation and formatting functions for external use |
src/commands/logs-stats.ts |
Command handler for awf logs stats with pretty format as default |
src/commands/logs-stats.test.ts |
Tests for stats command including source discovery and error handling |
src/commands/logs-summary.ts |
Command handler for awf logs summary with markdown format as default for GitHub Actions |
src/commands/logs-summary.test.ts |
Tests for summary command mirroring stats command test coverage |
src/cli.ts |
CLI integration adding stats and summary as subcommands of the logs command |
README.md |
User-facing documentation with usage examples for the new commands |
CLAUDE.md |
Developer documentation explaining the architecture and data structures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/commands/logs-summary.ts
Outdated
|
|
||
| /** | ||
| * Output format type for summary command | ||
| */ | ||
| export type SummaryFormat = 'json' | 'markdown' | 'pretty'; |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The StatsFormat and SummaryFormat types are defined separately in their respective command files but are identical. This creates potential for inconsistency if one is changed without updating the other.
Consider defining a shared type in a common location (e.g., src/types.ts) or simply reusing the same type:
export type LogStatsFormat = 'json' | 'markdown' | 'pretty';Then both commands can import and use this shared type.
| /** | |
| * Output format type for summary command | |
| */ | |
| export type SummaryFormat = 'json' | 'markdown' | 'pretty'; | |
| import type { StatsFormat } from './logs-stats'; | |
| /** | |
| * Output format type for summary command | |
| * | |
| * Alias of StatsFormat to ensure a single source of truth | |
| * for supported log output formats. | |
| */ | |
| export type SummaryFormat = StatsFormat; |
src/logs/stats-formatter.ts
Outdated
| .sort((a, b) => b.total - a.total); | ||
|
|
||
| // Calculate max domain length for alignment | ||
| const maxDomainLen = Math.max(...sortedDomains.map(d => d.domain.length), 0); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When all domains in the byDomain map are "-" (no valid domains), sortedDomains will be empty after filtering, which could cause Math.max(...sortedDomains.map(...)) on line 146 to return -Infinity. This would make maxDomainLen equal to -Infinity, causing unexpected padding behavior.
Consider adding a guard: const maxDomainLen = sortedDomains.length > 0 ? Math.max(...sortedDomains.map(d => d.domain.length)) : 0;
|
@copilot open a new pull request to apply changes based on the comments in this thread |
- Move duplicate StatsFormat/SummaryFormat types to shared LogStatsFormat in types.ts - Simplify colorize fallback using Proxy pattern instead of object literal - Add null checks for source.path and source.containerName before usage - Extract duplicated format validation into validateFormat helper function - Refactor duplicated command handler logic into shared logs-command-helpers module - Document intentional logging suppression difference between stats and summary commands - Fix uniqueDomains count discrepancy by showing valid domain count when "-" present - Add guard for empty sortedDomains to prevent -Infinity in maxDomainLen calculation Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
…#126) * Initial plan * refactor: address code review comments from PR #118 - Move duplicate StatsFormat/SummaryFormat types to shared LogStatsFormat in types.ts - Simplify colorize fallback using Proxy pattern instead of object literal - Add null checks for source.path and source.containerName before usage - Extract duplicated format validation into validateFormat helper function - Refactor duplicated command handler logic into shared logs-command-helpers module - Document intentional logging suppression difference between stats and summary commands - Fix uniqueDomains count discrepancy by showing valid domain count when "-" present - Add guard for empty sortedDomains to prevent -Infinity in maxDomainLen calculation Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Resolved README.md conflict - keeping simplified README that points to docs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
awf logs statscommand to show aggregated statistics from firewall logsawf logs summarycommand to generate summary reports (optimized for GitHub Actions)--format json|markdown|prettyfor flexible outputMotivation
This PR addresses the complexity of parsing firewall logs in GitHub Actions workflows. Previously, users had to write 150+ lines of custom JavaScript to parse Squid log files and generate summaries. Now this can be done with a single command:
New Commands
awf logs statsShows aggregated statistics in the terminal (default: pretty format):
awf logs summaryGenerates summary report (default: markdown format for GitHub Actions):
Output Examples
Pretty Format (terminal)
Markdown Format (GitHub Actions)
Test plan
awf logs stats --help,awf logs summary --help)🤖 Generated with Claude Code