Log Compression CLI Reference
The CLI is the primary distribution channel for LogStrip. It is published
to npm as logstrip and exposes one binary:
| Binary | Purpose |
|---|---|
logstrip | Log compression CLI - the sole entry point. |
The binary points at the compiled entry: dist/cli/index.js.
Synopsis
Section titled “Synopsis”logstrip [INPUT] [options]Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
INPUT | Path to a raw log file. When omitted, the CLI reads from stdin. Input that is plain text rather than a log is copied through (see Input that is not a log). |
Options
Section titled “Options”| Flag | Description | Default |
|---|---|---|
-o, --output <path> | Write the compressed log to <path>. When omitted, the compressed log is written to stdout. | (stdout) |
-a, --aggressiveness <level> | Compression preset: low, medium, high, aggressive, auto. | auto |
-m, --multiline <mode> | Multiline log joining: auto, python, node, java, go, rust, off. Joins continuation lines (indented tracebacks, stack frames) with their parent into a single logical line before processing. | off |
--severity <level> | Minimum severity to keep: fatal, error, warn, info, debug, trace. Lines below the given level are dropped. | (off) |
--include <regex> | Keep only lines matching this regex. All non-matching lines are dropped. | (off) |
--exclude <regex> | Drop lines matching this regex. Useful for suppressing known noise patterns like Downloading|Extracting. | (off) |
--sample <N> | Limit output to the first N kept lines. Useful for previewing large logs. | (off) |
--max-tokens <N> | Trim the compressed output to at most N tokens, keeping the highest-scoring lines first (LLM context-budget mode). Survivors stay in original order. | (off) |
--dedupe-window <N> | Collapse non-adjacent duplicate lines seen within the last N distinct lines into a single [xN] group. 1 keeps adjacent-only deduplication. | 1 |
--format-sample <N> | Majority-vote format-detection window: the number of leading non-blank lines sampled before the first-line format guess may be corrected. Robust to mixed-format logs (e.g. JSON interleaved with plaintext). | 50 |
--collapse-blocks <N> | Collapse consecutive repeats of a multi-line block (up to N lines) into a single copy followed by a [block xM] marker. Complements single-line [xN] deduplication. | (off) |
--no-collapse-stacks | Disable the automatic collapsing of repeated stack-trace windows that differ only in memory addresses, Go offsets or goroutine ids. | (auto on) |
--no-root-cause | Disable the automatic pruning of downstream cascade restatements (e.g. aborting due to previous errors, skipped because the upstream job failed). | (auto on) |
--no-multilingual | Disable the automatic detection of non-English error/failure/exception keywords (e.g. erreur, Fehler, fallo, ошибка, 错误). | (auto on) |
--no-adaptive-context | Disable the auto-mode adaptive context window. By default auto widens the after-error context around isolated errors and tightens it around clustered, self-contextualizing ones. | (auto on) |
--max-stack-frames <N> | Keep at most N consecutive application stack frames per trace; the rest collapse into a single [... K more application stack frames ...] marker. 0 keeps every frame. Internal library frames are still hidden separately. | 10 |
--no-template-mining | Disable template mining: by default near-identical lines that differ only in a number after a generic word label (e.g. Retrying job 17 / Retrying job 18), including numbers with a duration or size unit (took 120ms, uploaded 12MB) and parenthesized counters ((attempt 3)), and the response size that follows an HTTP status in access logs (502 157), fold into one [xN] group with a delta list. Numbers after diagnostic labels (code, status, exit, signal, line, version, errno, error) never merge. | (auto on) |
--no-collapse-repeated-blocks | Disable back-references for repeated blocks. By default a run of at least 3 output lines that repeats an earlier run from the last 400 output lines (typically the same stack trace printed again for the next failure, with a different header line or other output in between) is replaced by one [... N lines repeated from above ...] marker; back-to-back copies of the same block share one marker. Lines that cannot start a repeat are written immediately, so streaming stays bounded in memory. | (auto on) |
--no-json-report | Disable structured JSON document detection. By default an input that is a whole JSON document (test-runner report, scanner export) is compressed semantically instead of line-by-line: string values are sanitized, empty fields pruned, a field repeating an earlier sibling becomes a [logstrip:= field] reference, and array entries identical except for unique identifier fields collapse into one entry with a [logstrip:group] header listing each grouped entry’s identifiers. The output stays valid JSON. Inputs larger than 8 MiB, JSONL streams (pino/bunyan) and lone JSON log lines with a level field keep using the line pipeline. | (auto on) |
--force | Compress even when the input does not look like a log. Disables the text passthrough that copies prose, markdown, source code and configuration files through (see Input that is not a log). | off |
--preserve-id-suffix <N> | Keep the last N characters of redacted UUIDs and hashes (e.g. [ID:174000], [HASH:0a1b2c]) instead of fully masking them to [ID] / [HASH]. Useful when trailing identifier digits help correlate events across lines. Range 0–16; 0 masks fully. | 0 |
--max-line-length <n> | Truncate lines longer than n characters. Very long lines (e.g. minified bundles) are replaced with [TRUNCATED]. | 100000 |
--timeout <s> | Stop processing after s seconds. The output is flushed and timedOut: true is set in the result. | (off) |
--progress | Show a progress bar on stderr (file input only, requires --output). | off |
-s, --stats | Print compression statistics to stderr after the log has been processed. | off |
-j, --json | Print the LogStripResult as JSON to stdout. Requires --output so the compressed log does not collide with the report. | off |
-h, --help | Print the help text and exit. | - |
-v, --version | Print the CLI version and exit. | - |
--config <path> | Path to a .logstrip.yml custom config file. When omitted, the CLI auto-detects .logstrip.yml in the current working directory. | (auto) |
--telemetry | Print cumulative telemetry summary to stderr and exit. No compression is performed. | off |
I/O contract
Section titled “I/O contract”- The compressed log goes to
--outputwhen set, otherwise tostdout. - Stats (
--stats) always go tostderrso they never collide with the compressed log onstdout. - The JSON report (
--json) always goes tostdout. To prevent contamination,--jsonrequires--output. - When
INPUTis omitted andstdinis a terminal (TTY), the CLI exits with code2rather than waiting forever for input. - Output starts once the first lines have been classified as log or text. A
log with recognizable structure (timestamps, severity tags, stack frames) is
settled after about 8 non-blank lines, so
tail -f app.log | logstripstarts almost at once. Text, and a log with little structure, can wait for the full sample: up to 100 non-blank lines or 256 KiB, whichever comes first, which is the worst case. With--forcenothing is buffered and output starts with the first line.
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 | Success. |
1 | Runtime failure (file not found, stream error, internal exception). |
2 | Usage error (unknown flag, unsupported aggressiveness, --json without --output, stdin is a TTY). |
When the reader of stdout goes away early (logstrip raw.log | head), the run
stops quietly with exit code 0, like cat does, instead of reporting the
broken pipe as a failure.
Recipes
Section titled “Recipes”File in, file out
Section titled “File in, file out”logstrip raw.log -o clean.logStdin in, stdout out
Section titled “Stdin in, stdout out”cat raw.log | logstrip > clean.logPowerShell:
Get-Content raw.log | logstrip > clean.logStats alongside content
Section titled “Stats alongside content”logstrip raw.log --stats > clean.log# compressed log -> clean.log# stats -> stderr (visible in the terminal or CI summary)Machine-readable report
Section titled “Machine-readable report”logstrip raw.log -o clean.log --jsonstdout will contain a LogStripResult object:
{ "stats": { "inputLines": 4128, "outputLines": 312, "inputWords": 21450, "outputWords": 4138, "inputBytes": 412800, "outputBytes": 31200, "droppedLines": 3640, "duplicateLines": 87, "hiddenInternalStackLines": 89, "truncatedLines": 3 }, "inputTokens": 27885, "outputTokens": 5379, "savedTokens": 22506, "savingsPercent": 80.71, "detectedSources": ["webpack", "npm", "kubernetes"], "detectedFormat": "node", "contentKind": "log", "timedOut": false, "outputPath": "clean.log"}detectedSources is ranked by lightweight source fingerprints gathered during
streaming. It is informational and does not change the compressed log output.
detectedFormat indicates the inferred log format (e.g. node, python,
java, go). contentKind is log when the input went through the
compression pipeline and text when it was copied through unchanged (see
below); it is absent when --timeout fired before the input was classified.
timedOut is true when --timeout was reached before the full stream was
processed.
Input that is not a log
Section titled “Input that is not a log”LogStrip scores every line as noise or signal, which is right for build and server logs and destructive for a README, a YAML file or a source file. So it looks at the first 100 non-blank lines of the input (at most 256 KiB) and decides whether it is a log or plain text:
- Log signals: timestamps, severity tags (
[INFO],ERROR:), CI markers (npm ERR!,::error::,FAIL,make[1]), stack frames and tracebacks, logfmt / JSON-line / syslog records, access-log lines, ANSI escapes and known tool output. - Text signals: markdown (headings, lists, tables, links, fences), prose sentences, source code, YAML / INI / JSON configuration, shell scripts and Dockerfiles, HTML, CSV.
Plain text is copied through line by line, nothing is dropped and the savings
are 0%. Anything that is not clearly text is still compressed as a log, so
logs in formats LogStrip does not recognise keep working, and a log that opens
with a short prose banner stays a log.
logstrip README.md --stats > copy.md# stderr: ... content kind : text (passed through, secrets masked)Passthrough leaves the text unchanged except for credentials. Tokens,
passwords and secret fields, connection-string passwords, Authorization
headers, AWS and other vendor keys, high-entropy tokens and PEM private key
blocks are masked with the same rules the compressor uses (a private key’s
lines are dropped and counted). Identifiers, timestamps, IP addresses, emails
and prose are not touched, so a file without secrets comes out as it went in,
apart from line endings being normalized to \n and a final newline being
added. The masking favours safety over fidelity, so an assignment in source
code such as const accessToken = load() or a sentence that mentions an
Authorization: header is masked too. An unquoted type
(previousToken: string), a plain unquoted environment read
(process.env.NPM_TOKEN) and a GitHub permission (id-token: write) are not. A page that
only names the private key header (-----BEGIN PRIVATE KEY-----) inside a
sentence or table is left alone; only a header that ends its line opens a key
block. Filters such as --include, --exclude, --severity, --sample,
--max-tokens and --max-line-length do not apply to passed-through text;
custom sanitizePatterns from .logstrip.yml do.
The decision is made from the first sampled lines only. If LogStrip takes a
log for text (for example a log that begins with a long stretch of
configuration-like output), or you want a text file compressed anyway, pass
--force:
logstrip output.txt --force -o clean.logThe hooks of the agent plugins use the same check, see Plugins.
Multiline traceback joining
Section titled “Multiline traceback joining”Python tracebacks and Node.js stack traces span multiple indented lines.
Use -m to join continuation lines with their parent into a single logical
line before scoring and deduplication:
logstrip traceback.log -m python -o clean.loglogstrip crash.log -m node -o clean.loglogstrip mixed.log -m auto -o clean.logSupported modes:
| Mode | Continuation detection |
|---|---|
python | Indented lines (e.g. File "app.py", line 42) |
node | Indented lines (e.g. at app (/src/app.ts:10:5)) |
java | Indented lines + Caused by: headers |
go | Tab-indented lines + goroutine N [status]: headers |
rust | Indented lines |
auto | Combines all of the above; best for mixed-language logs |
off | No joining (default) |
Groups are bounded at 200 lines / 200 KB to prevent unbounded memory growth from pathological input.
Severity filtering
Section titled “Severity filtering”Keep only lines at or above a given severity level:
logstrip raw.log --severity error -o clean.log # errors + fatals onlylogstrip raw.log --severity warn -o clean.log # warnings + errors + fatals| Level | What passes |
|---|---|
fatal | FATAL, CRITICAL, EMERG, ALERT |
error | Above + ERROR, ERR, SEV2 |
warn | Above + WARN, WARNING |
info | Above + INFO |
debug | Above + DEBUG |
trace | All levels pass |
Severity is inferred from log-level tags, JSON level fields, and common
abbreviations. Lines with no detectable severity always pass the filter.
Include / exclude patterns
Section titled “Include / exclude patterns”# Keep only lines mentioning "timeout" or "refused"logstrip raw.log --include 'timeout|refused' -o clean.log
# Drop download/extract progress noiselogstrip build.log --exclude 'Downloading|Extracting|Progress' -o clean.logBoth flags accept JavaScript-compatible regex patterns. When --include is
set, any line that does not match is dropped. When --exclude is set, any
line that matches is dropped. They can be combined.
Sampling and timeouts
Section titled “Sampling and timeouts”# Preview the first 50 significant lines of a huge loglogstrip huge.log --sample 50 -o preview.log
# Stop processing after 30 seconds (CI time budgets)logstrip raw.log --timeout 30 -o clean.logWhen --timeout fires, the output is flushed and the result includes
timedOut: true. The compressed output is still valid and usable.
Progress bar
Section titled “Progress bar”logstrip huge.log --progress -o clean.logShows a live progress bar on stderr (file input only, requires --output).
Useful when compressing multi-gigabyte logs locally.
Aggressiveness and context retention
Section titled “Aggressiveness and context retention”--aggressiveness controls how much context survives around high-signal lines.
The parser uses a hybrid scoring model instead of a single binary filter:
- hard signals (
[ERROR], JSON"level":"error", scanner findings, container failures, npm/yarn errors, stack frames) are emitted immediately; - nearby soft lines are kept through a small before/after context window;
- repeated sanitized lines are dampened so spam eventually falls below the keep threshold;
- adjacent diagnostic variants with the same stable shape are folded as delta
summaries, so repeated lines like
amount=99.99,amount=49.50, andamount=12.00render as[x3] ... amount=[99.99 | 49.50 | 12.00]; aggressivestill drops pure warning noise, but preserves warning lines with diagnostic keywords such asfailed,timeout,refused,crashed,killed,terminated,unauthorized, andunavailable.
Static levels
Section titled “Static levels”| Level | Behavior |
|---|---|
low | Keeps most lines including [INFO] and [DEBUG]. Minimal compression. |
medium | Drops noise tags ([INFO], [DEBUG], [TRACE]) but keeps [WARN]. |
high | Drops noise and pure warnings; keeps only diagnostic signals + context window. |
aggressive | Drops everything except errors, fatals, stack frames, and explicit diagnostic keywords. Maximum compression. |
auto mode (default)
Section titled “auto mode (default)”auto starts at the high static level and then adjusts dynamically based
on what the parser sees in the stream:
- The parser tracks a sliding window of the last 8 line decisions (kept vs dropped).
- When the window contains mostly hard-keep signals (3+ errors/diagnostics),
the effective level decreases toward
medium- more context is preserved because the log is signal-rich. - When the window shows many drops and repeated lines (6+ drops + repeats),
the effective level increases toward
aggressive- the log is mostly noise, so stricter filtering recovers more tokens.
This means auto is safe to use as the default: it preserves context in
error-heavy logs and maximizes compression in noisy build output, without
requiring the user to guess the right level up front.
To pin a specific static level and disable dynamic adjustment, pass it explicitly:
logstrip raw.log -a high -o clean.logUse inside a shell script
Section titled “Use inside a shell script”#!/usr/bin/env bashset -euo pipefail
logstrip raw.log -o clean.log --json | jq '.savingsPercent'Stats block format
Section titled “Stats block format”When --stats is enabled the CLI writes a fixed-shape block to stderr:
LogStrip compression report input lines : <int> output lines : <int> dropped lines : <int> duplicate lines : <int> hidden internal : <int> input tokens : <int> output tokens : <int> saved tokens : <int> savings : <float>% content kind : <log | text (passed through, secrets masked)> output path : <path> # only when --output was setThis format is stable across patch releases. If you need to parse it from
shell, prefer --json instead.
Telemetry
Section titled “Telemetry”LogStrip automatically records cumulative token-savings telemetry after
every successful run. The data is stored locally in
~/.logstrip/telemetry.json and never sent anywhere. To override the
storage directory, set the LOGSTRIP_TELEMETRY_DIR environment variable.
View the summary
Section titled “View the summary”logstrip --telemetryOutput (written to stderr):
LogStrip Telemetry total runs : 42 input tokens : 2,145,000 output tokens : 413,800 saved tokens : 1,731,200 average savings : 80.71% last run : 2026-05-21T14:30:00.000Z
Last 5 runs: 2026-05-21T14:30:00 saved=52,000 (80.0%) 2026-05-21T14:15:00 saved=48,000 (78.5%) ...The store keeps at most 1,000 entries; older entries are pruned automatically. A run that copied text through (see Input that is not a log) saves nothing and is not recorded, so it does not drag down the average savings.
Update notifications
Section titled “Update notifications”When stderr is attached to a terminal, logstrip checks the npm
registry once every 24 hours and prints a single line to stderr if a
newer release is available:
logstrip: update available 1.8.0 → 1.9.0 (npm i -g logstrip)The check is best-effort and never affects the exit code, stdout output or your pipeline. It is skipped automatically in the following cases:
- when
stderris redirected (CI logs, files, pipes), - when
--jsonis used (machine-readable mode stays clean), - when the
LOGSTRIP_NO_UPDATE_CHECKenvironment variable is set to any non-empty value.
The last-known latest version is cached at
~/.logstrip/.cache/version.json for 24 hours. Override the cache
directory with the LOGSTRIP_CACHE_DIR environment variable.
Embedding in Node
Section titled “Embedding in Node”If you’d rather call the CLI from JavaScript without spawning a subprocess, import the helper directly:
import { runCli } from 'logstrip/cli';
const exitCode = await runCli(['raw.log', '-o', 'clean.log', '--json'], { stdin: process.stdin, stdout: process.stdout, stderr: process.stderr, stdinIsTTY: Boolean(process.stdin.isTTY), stderrIsTTY: Boolean(process.stderr.isTTY),});For library-style integration that returns a LogStripResult directly, use
processLogFile / processLogStream instead.
Custom configuration (.logstrip.yml)
Section titled “Custom configuration (.logstrip.yml)”Corporations and teams running internal tools can extend LogStrip
without modifying the source code. Create a .logstrip.yml file in the
repository root (or pass --config path/to/config.yml) to define custom
log sources, diagnostic patterns, ignore rules, sanitization rules, and
internal stack patterns that merge with the built-in set at runtime.
File format
Section titled “File format”# Custom log sources - markers are case-insensitive substrings# matched against every line. If a source name matches a built-in# source, the markers are merged (deduplicated).sources: - name: acme-gateway markers: - acme-gateway - "[ACME-GW]" - name: acme-auth markers: [acme-auth-service, "[ACME-AUTH]"]
# Lines matching any of these regexes receive a +50 relevance boost,# same as built-in DIAGNOSTIC_PATTERN.diagnosticPatterns: - "ACME_ERROR_\\d+" - "\\bACME-FATAL\\b"
# Lines matching any of these regexes are dropped early (before# sanitization and scoring), similar to built-in IGNORED_LOG_TAG_PATTERN.ignorePatterns: - "\\bACME-HEARTBEAT\\b" - "\\bacme-metrics\\b"
# Each rule applies a regex replacement to every line after built-in# sanitization. Use "flags" to control regex flags (default: "gu").sanitizePatterns: - pattern: "\\bACME-USER-\\d+\\b" replacement: "[ACME-USER]" - pattern: "acme-tenant/[a-z0-9-]+" replacement: "acme-tenant/[ID]" flags: "gi"
# Lines matching any of these regexes are collapsed behind the# [internal-stack] marker, same as built-in INTERNAL_STACK patterns.internalStackPatterns: - "/opt/acme/lib/"How it works
Section titled “How it works”- Auto-detection - When
--configis not provided, the CLI looks for.logstrip.ymlin the current working directory. If the file does not exist, processing continues with built-in patterns only. - Merging - Custom sources with a name that already exists in the
built-in set (e.g.
docker) have their markers merged with the built-in markers. New source names are appended. - Order of application - Custom ignore patterns are checked before built-in noise-tag filtering. Custom sanitize rules run after built-in sanitization. Custom diagnostic patterns add +50 to the relevance score (same weight as built-in diagnostics). Custom internal-stack patterns are checked alongside built-in ones.
- Zero runtime dependencies - The YAML subset parser is built into
logstrip-config.tsand handles the constructs shown above (mappings, sequences, inline arrays, quoted and unquoted strings, comments). It does not requirejs-yamlor any external package.
Example: internal CI platform
Section titled “Example: internal CI platform”# .logstrip.yml - Acme Corp CI extensionsources: - name: acme-ci markers: [acme-ci-runner, "[ACME-CI]"]
diagnosticPatterns: - "ACME_BUILD_FAILED" - "ACME_TEST_TIMEOUT"
ignorePatterns: - "\\bacme-ci heartbeat\\b" - "\\bacme-ci version check\\b"
sanitizePatterns: - pattern: "ACME-EMP-\\d{6}" replacement: "[ACME-EMP]"
internalStackPatterns: - "/opt/acme/ci-runner/"Then simply run:
logstrip ci-output.log -o clean.log# .logstrip.yml is auto-detected from the current directoryOr explicitly:
logstrip ci-output.log -o clean.log --config /etc/logstrip/acme.yml