|
1 | 1 | # Logging Quick Reference |
2 | 2 |
|
3 | | -## View Logs |
| 3 | +## Using the AWF CLI |
| 4 | + |
| 5 | +The firewall includes a built-in `awf logs` command for viewing and analyzing Squid proxy logs: |
| 6 | + |
| 7 | +### View Logs in Real-Time |
| 8 | + |
| 9 | +```bash |
| 10 | +# Follow logs in real-time (like tail -f) |
| 11 | +awf logs -f |
| 12 | + |
| 13 | +# Follow with PID tracking to identify which process made each request |
| 14 | +awf logs -f --with-pid |
| 15 | + |
| 16 | +# Follow with JSON output |
| 17 | +awf logs -f --format json |
| 18 | +``` |
| 19 | + |
| 20 | +### View Historical Logs |
| 21 | + |
| 22 | +```bash |
| 23 | +# View logs from last run (pretty format, default) |
| 24 | +awf logs |
| 25 | + |
| 26 | +# View logs from specific directory |
| 27 | +awf logs --source /tmp/squid-logs-1234567890 |
| 28 | + |
| 29 | +# Raw format (no colorization) |
| 30 | +awf logs --format raw |
| 31 | + |
| 32 | +# JSON format for scripting |
| 33 | +awf logs --format json |
| 34 | +``` |
| 35 | + |
| 36 | +### List Available Log Sources |
| 37 | + |
| 38 | +```bash |
| 39 | +# Find all preserved log directories |
| 40 | +awf logs --list |
| 41 | +``` |
| 42 | + |
| 43 | +### Generate Statistics |
| 44 | + |
| 45 | +```bash |
| 46 | +# Show aggregated stats (pretty terminal output) |
| 47 | +awf logs stats |
| 48 | + |
| 49 | +# JSON format for scripting |
| 50 | +awf logs stats --format json |
| 51 | + |
| 52 | +# Markdown format |
| 53 | +awf logs stats --format markdown |
| 54 | +``` |
| 55 | + |
| 56 | +### Generate Summary for GitHub Actions |
| 57 | + |
| 58 | +```bash |
| 59 | +# Add summary to GitHub Actions step summary |
| 60 | +awf logs summary >> $GITHUB_STEP_SUMMARY |
| 61 | + |
| 62 | +# Also available in JSON and pretty formats |
| 63 | +awf logs summary --format json |
| 64 | +``` |
| 65 | + |
| 66 | +**CLI Options:** |
| 67 | +| Flag | Description | |
| 68 | +|------|-------------| |
| 69 | +| `-f, --follow` | Follow log output in real-time (like `tail -f`) | |
| 70 | +| `--format <format>` | Output format: `raw`, `pretty`, `json` | |
| 71 | +| `--source <path>` | Path to log directory or `"running"` for live container | |
| 72 | +| `--list` | List available log sources | |
| 73 | +| `--with-pid` | Enrich logs with PID/process info (requires `-f`) | |
| 74 | + |
| 75 | +**Statistics Commands:** |
| 76 | +| Command | Description | |
| 77 | +|---------|-------------| |
| 78 | +| `awf logs stats` | Show aggregated statistics (total requests, allowed/denied counts, per-domain breakdown) | |
| 79 | +| `awf logs summary` | Generate markdown summary (optimized for GitHub Actions) | |
| 80 | + |
| 81 | +## Manual Docker Commands |
| 82 | + |
| 83 | +For advanced use cases or when the CLI is not available, you can access logs directly via Docker: |
4 | 84 |
|
5 | 85 | ### HTTP/HTTPS Traffic (Squid) |
6 | 86 | ```bash |
@@ -121,23 +201,9 @@ docker exec awf-squid grep "TCP_DENIED" /var/log/squid/access.log | \ |
121 | 201 |
|
122 | 202 | ## PID/Process Tracking |
123 | 203 |
|
124 | | -Correlate network requests with specific processes using `awf logs -f --with-pid`: |
125 | | - |
126 | | -```bash |
127 | | -# Follow logs with PID tracking (real-time only) |
128 | | -awf logs -f --with-pid |
129 | | - |
130 | | -# Example output: |
131 | | -# [2024-01-01 12:00:00.123] CONNECT api.github.com → 200 (ALLOWED) [curl/7.88.1] <PID:12345 curl> |
132 | | -``` |
| 204 | +The `awf logs` command supports real-time PID tracking using the `--with-pid` flag (see "Using the AWF CLI" section above for examples). |
133 | 205 |
|
134 | | -### JSON Output with PID |
135 | | - |
136 | | -```bash |
137 | | -awf logs -f --with-pid --format json |
138 | | -``` |
139 | | - |
140 | | -**Additional fields when `--with-pid` is enabled:** |
| 206 | +When enabled, logs include: |
141 | 207 | | Field | Description | |
142 | 208 | |-------|-------------| |
143 | 209 | | `pid` | Process ID that made the request | |
@@ -226,30 +292,6 @@ docker exec awf-squid grep "curl" /var/log/squid/access.log |
226 | 292 |
|
227 | 293 | ## Statistics |
228 | 294 |
|
229 | | -### Using `awf logs stats` |
230 | | - |
231 | | -Get aggregated statistics including total requests, allowed/denied counts, and per-domain breakdown: |
232 | | - |
233 | | -```bash |
234 | | -# Pretty terminal output (default) |
235 | | -awf logs stats |
236 | | - |
237 | | -# JSON format for scripting |
238 | | -awf logs stats --format json |
239 | | - |
240 | | -# Markdown format |
241 | | -awf logs stats --format markdown |
242 | | -``` |
243 | | - |
244 | | -### Using `awf logs summary` for GitHub Actions |
245 | | - |
246 | | -Generate a markdown summary optimized for GitHub Actions step summaries: |
247 | | - |
248 | | -```bash |
249 | | -# Add summary to GitHub Actions step summary |
250 | | -awf logs summary >> $GITHUB_STEP_SUMMARY |
251 | | -``` |
252 | | - |
253 | 295 | ### Manual Statistics Queries |
254 | 296 |
|
255 | 297 | #### Total Requests |
|
0 commit comments