CLI Usage¶
The PyLogShield CLI provides an interactive way to view and follow log files directly from your terminal with rich formatting.
Overview¶
Features¶
- Search log with specific keywords
- Filter specific log level ('info', 'debug', 'error', etc)
- Limit the number of logs to display in the console
Usage: pylogshield [OPTIONS] COMMAND [ARGS]...
Commands:
follow Live-follow a log file (tail -f style) with a rich table that updates in place.
levels List supported log levels and their numeric values.
view Pretty-print logs from a file, attempting JSON first and falling back to plain text.
Commands¶
| Command | Description |
|---|---|
tui |
๐ฅ๏ธ Full-screen interactive TUI viewer with live search, filters, and export. |
view |
๐ View the last N logs from a file with optional level and keyword filtering. |
follow |
๐ก Live view, auto-refreshes output on new log lines. |
levels |
๐ Show all valid logging levels. |
Common Options¶
| Option | Short | Description |
|---|---|---|
--file |
-f |
Log file path (required for view/follow) |
--limit |
-n |
Number of lines to display (view only) |
--level |
-l |
Filter logs by log level (e.g., INFO, ERROR) |
--keyword |
-k |
Filter logs containing this text (case-insensitive) |
--interval |
-i |
Refresh interval in seconds (follow only) |
--max-lines |
-m |
Maximum lines in live view buffer (follow only) |
Interactive TUI Viewer¶
The TUI provides a full-screen log viewer with live search, multi-filter, export, and live-follow mode โ all keyboard-driven, no browser required.
Launch¶
# Open a log file in the TUI
pylogshield tui --file ~/.logs/myapp.log
# Start with ERROR+ level filter already applied
pylogshield tui --file app.log --level ERROR
# Start directly in live-follow mode
pylogshield tui --file app.log --follow
# Combine: follow only critical issues
pylogshield tui --file app.log --level CRITICAL --follow
Options¶
| Option | Short | Description |
|---|---|---|
--file |
-f |
Path to the log file (required) |
--level |
-l |
Pre-apply a minimum level filter on launch (e.g. ERROR) |
--follow |
Start in live-follow mode |
Keyboard Reference¶
| Key | Action |
|---|---|
/ |
Focus the search bar โ rows filter as you type |
Ctrl+R |
Toggle regex search mode |
Esc |
Clear search or close any modal |
โ โ |
Navigate rows |
PgUp PgDn |
Page up / down |
Home / End |
First / last row (End also resumes live follow) |
Enter |
Expand full row detail (all fields, raw line) |
Ctrl+F |
Open filter panel (level, time range, logger name) |
F |
Toggle live-follow mode |
E |
Open export modal |
? |
Show keyboard reference |
Q / Ctrl+C |
Quit |
Search¶
Type / to focus the search bar. Rows are filtered instantly as you type, and matching text is highlighted bold in the Message column.
Enable regex with Ctrl+R โ the [re] indicator appears in the search bar:
# Plain text search
/payment
# Regex โ match "ERROR" or "CRITICAL" messages
/^(ERROR|CRITICAL)
Filter Panel (Ctrl+F)¶
The filter panel stacks multiple filters with AND logic:
- Level toggles โ show only CRITICAL, ERROR, WARNING, INFO, DEBUG (any combination)
- Time range โ Last 1h, Last 6h, Last 24h, or All time
- Logger name โ substring match against the logger name field
Active filters appear as removable chips in the bar below the log table. Press R inside the panel to reset all filters to defaults.
Live Follow Mode (F)¶
Press F to toggle live-follow โ new log lines appear automatically as they are written to the file. The top bar shows โ LIVE in green when active.
Scrolling up automatically pauses follow to let you read without the view jumping. A yellow banner confirms the pause:
Press End to jump to the bottom and resume.
Export (E)¶
Opens a modal to export the currently filtered view (not the full file):
| Format | Output | Use case |
|---|---|---|
| CSV | UTF-8 with BOM | Open directly in Excel / Google Sheets |
| JSON | Indented array of objects | Programmatic processing, log pipelines |
| Plain text | One line per row | Copy-paste, ticket attachments |
| HTML report | Self-contained file with stats header | Share with stakeholders via email |
Files are saved to the current working directory with an auto-generated name:
myapp-export-2026-05-09.csv
myapp-export-2026-05-09.json
myapp-export-2026-05-09.txt
myapp-export-2026-05-09.html
Row Detail (Enter)¶
Press Enter on any row to open a detail panel showing every field:
Row Detail
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Timestamp: 2026-05-09 00:12:04.221
Level: ERROR
Logger: payments
Location: payments:88
Message: Payment failed order_id=ORD-002 reason=card_declined
Extra: {"gateway": "stripe"}
2026-05-09 00:12:04.221 ERROR payments payments:88 Payment failed...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Esc to close
โถ๏ธ View Logs (Plain or JSON)¶
Display the last N lines from a log file in a formatted table.
Basic Usage¶
Limit Number of Lines¶
pylogshield view --file logs/app.log --limit 50
# or short form
pylogshield view -f logs/app.log -n 50
Filter by Log Level¶
Show only logs at or above a certain level:
Filter by Keyword¶
Show only logs containing a specific keyword:
pylogshield view -f logs/app.log --keyword "database"
pylogshield view -f logs/app.log -k timeout
Combined Filters¶
Follow Logs (Live)¶
Live-follow a log file with automatic updates, similar to tail -f.
Basic Usage¶
Press Ctrl+C to stop following.
With Level Filter¶
With Keyword Filter¶
Custom Refresh Interval¶
Set how often the display updates (default: 0.5 seconds):
pylogshield follow -f logs/app.log --interval 1.0
# or
pylogshield follow -f logs/app.log -i 0.25
Limit Buffer Size¶
Control how many lines are kept in the live view (default: 500):
pylogshield follow -f logs/app.log --max-lines 200
# or
pylogshield follow -f logs/app.log -m 1000
Full Example¶
Show Log Levels¶
Display all supported log levels and their numeric values:
Output:
โญโโโโโโโโโโโฌโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Level โ Value โ Description โ
โโโโโโโโโโโโผโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ CRITICAL โ 50 โ System failure โ immediate attention reqโฆ โ
โ ERROR โ 40 โ An operation failed โ
โ WARNING โ 30 โ Unexpected condition, app still running โ
โ INFO โ 20 โ General operational messages โ
โ DEBUG โ 10 โ Detailed diagnostic information โ
โ NOTSET โ 0 โ No level assigned โ
โฐโโโโโโโโโโโดโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Examples¶
View last 50 ERROR logs containing "timeout"¶
Follow production logs for critical issues¶
View JSON-formatted logs¶
The CLI automatically detects and parses JSON log format:
Monitor multiple keywords¶
Run multiple follow sessions in different terminals:
# Terminal 1: Watch for authentication issues
pylogshield follow -f app.log -k "auth"
# Terminal 2: Watch for database issues
pylogshield follow -f app.log -k "database"
Tips¶
-
Log file location: By default, PyLogShield writes to
~/.logs/<logger_name>.log -
JSON vs Plain text: The CLI automatically detects the log format and parses accordingly
-
Large files: For very large log files, use
--limitto avoid memory issues -
Log rotation: The
followcommand automatically handles log rotation (detects when the file is truncated) -
Performance: Use a longer
--intervalfor lower CPU usage when following logs