Skip to content

Commit 8d172fe

Browse files
CopilotMossaka
andauthored
docs: add documentation for awf logs command (#73)
* Initial plan * docs: add documentation for awf logs command Co-authored-by: Mossaka <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Mossaka <[email protected]>
1 parent ed062d4 commit 8d172fe

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ sudo awf \
5252

5353
**Note:** Always use the `--` separator to pass commands and arguments. This ensures proper argument handling and avoids shell escaping issues.
5454

55+
### Log Viewing
56+
57+
View Squid proxy logs from current or previous runs:
58+
59+
```bash
60+
# View recent logs with pretty formatting
61+
awf logs
62+
63+
# Follow logs in real-time
64+
awf logs -f
65+
66+
# View logs in JSON format for scripting
67+
awf logs --format json
68+
69+
# List all available log sources
70+
awf logs --list
71+
```
72+
5573
## Domain Whitelisting
5674

5775
Domains automatically match all subdomains:

docs-site/src/content/docs/reference/cli-reference.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,59 @@ Working directory inside the container.
139139
| `130` | Interrupted by SIGINT (Ctrl+C) |
140140
| `143` | Terminated by SIGTERM |
141141

142+
## Subcommands
143+
144+
### `awf logs`
145+
146+
View Squid proxy logs from current or previous runs.
147+
148+
```bash
149+
awf logs [options]
150+
```
151+
152+
#### Options
153+
154+
| Option | Type | Default | Description |
155+
|--------|------|---------|-------------|
156+
| `-f, --follow` | flag | `false` | Follow log output in real-time |
157+
| `--format <format>` | string | `pretty` | Output format: `raw`, `pretty`, `json` |
158+
| `--source <path>` | string | auto | Path to log directory or `running` for live container |
159+
| `--list` | flag | `false` | List available log sources |
160+
161+
#### Output Formats
162+
163+
| Format | Description |
164+
|--------|-------------|
165+
| `pretty` | Colorized, human-readable output (default) |
166+
| `raw` | Logs as-is without parsing |
167+
| `json` | Structured JSON for scripting |
168+
169+
#### Examples
170+
171+
```bash
172+
# View recent logs with pretty formatting
173+
awf logs
174+
175+
# Follow logs in real-time
176+
awf logs -f
177+
178+
# View logs in JSON format
179+
awf logs --format json
180+
181+
# List available log sources
182+
awf logs --list
183+
184+
# Use a specific log directory
185+
awf logs --source /tmp/squid-logs-1234567890
186+
187+
# Stream from running container
188+
awf logs --source running -f
189+
```
190+
191+
:::note
192+
Log sources are auto-discovered in this order: running containers, `AWF_LOGS_DIR` environment variable, then preserved log directories in `/tmp/squid-logs-*`.
193+
:::
194+
142195
## See Also
143196

144197
- [Quick Start Guide](/gh-aw-firewall/quickstart) - Getting started with examples

docs/usage.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,99 @@ docker logs awf-squid
353353
# /tmp/awf-<timestamp>/squid-logs/
354354
```
355355

356+
## Viewing Logs with `awf logs`
357+
358+
The `awf logs` command provides an easy way to view Squid proxy logs from current or previous runs.
359+
360+
### Basic Usage
361+
362+
```bash
363+
# View recent logs with pretty formatting (default)
364+
awf logs
365+
366+
# Follow logs in real-time (like tail -f)
367+
awf logs -f
368+
```
369+
370+
### Output Formats
371+
372+
The command supports three output formats:
373+
374+
```bash
375+
# Pretty: colorized, human-readable output (default)
376+
awf logs --format pretty
377+
378+
# Raw: logs as-is without parsing or colorization
379+
awf logs --format raw
380+
381+
# JSON: structured output for programmatic consumption
382+
awf logs --format json
383+
```
384+
385+
Example JSON output:
386+
```json
387+
{"timestamp":1760987995.318,"clientIp":"172.20.98.20","clientPort":"55960","domain":"example.com","destIp":"-","destPort":"-","httpVersion":"1.1","method":"CONNECT","statusCode":403,"decision":"TCP_DENIED:HIER_NONE","url":"example.com:443","userAgent":"curl/7.81.0","isAllowed":false}
388+
```
389+
390+
### Log Source Discovery
391+
392+
The command auto-discovers log sources in this order:
393+
1. Running `awf-squid` container (live logs)
394+
2. `AWF_LOGS_DIR` environment variable (if set)
395+
3. Preserved log directories in `/tmp/squid-logs-<timestamp>`
396+
397+
```bash
398+
# List all available log sources
399+
awf logs --list
400+
401+
# Output example:
402+
# Available log sources:
403+
# [running] awf-squid (live container)
404+
# [preserved] /tmp/squid-logs-1760987995318 (11/27/2024, 12:30:00 PM)
405+
# [preserved] /tmp/squid-logs-1760987890000 (11/27/2024, 12:28:10 PM)
406+
```
407+
408+
### Using Specific Log Sources
409+
410+
```bash
411+
# Stream from a running container
412+
awf logs --source running -f
413+
414+
# Use a specific preserved log directory
415+
awf logs --source /tmp/squid-logs-1760987995318
416+
417+
# Use logs from AWF_LOGS_DIR
418+
export AWF_LOGS_DIR=/path/to/logs
419+
awf logs
420+
```
421+
422+
### Combining Options
423+
424+
```bash
425+
# Follow live logs in JSON format
426+
awf logs -f --format json
427+
428+
# View specific logs in raw format
429+
awf logs --source /tmp/squid-logs-1760987995318 --format raw
430+
```
431+
432+
### Troubleshooting with Logs
433+
434+
**Find blocked requests:**
435+
```bash
436+
awf logs --format json | jq 'select(.isAllowed == false)'
437+
```
438+
439+
**Filter by domain:**
440+
```bash
441+
awf logs --format json | jq 'select(.domain | contains("github"))'
442+
```
443+
444+
**Count blocked vs allowed:**
445+
```bash
446+
awf logs --format json | jq -s 'group_by(.isAllowed) | map({allowed: .[0].isAllowed, count: length})'
447+
```
448+
356449
## Log Analysis
357450

358451
Find all blocked domains:

0 commit comments

Comments
 (0)