Skip to main content

English · Русский

logfold

A library and command-line tool for large logs: folds lines into templates and compares two runs.

CI PyPI Python versions License: MIT Rust core


logfold reads a log and replaces the variable parts of messages (numbers, IP addresses, UUIDs, paths) with masks. Lines with the same text are then grouped into templates. For every template it counts the records, the first and last time it appeared, the highest severity level and an example line. The diff command compares two runs, for example before and after a deploy, and shows the templates that are new, gone or noticeably changed in share.

The core is written in Rust; you can use it from Python or from the command line. Everything runs locally and no data is sent anywhere.

$ logfold diff before.log after.log --out diff.html --fail-on-new
before.log -> after.log: 1,265,631 -> 1,246,573 records, 2 new (2 WARN+), 1 disappeared, 3 changed, 9 unchanged, native engine, 3.41s

New templates (2)
    before      after    change  level  template
         0     44,102       new  ERROR  circuit breaker opened for upstream <IP>
         0     44,310       new  WARN   queue depth <NUM> exceeds limit on worker-<NUM>

What it does

  • Templates. user alice failed login from 10.0.0.7 and the other lines like it are reduced to one entry, user <*> failed login from <IP>. The algorithm is compatible with Drain3. Average grouping accuracy on the 16 Loghub-2k datasets: Drain3 0.7658, logfold in sequential mode 0.7658, in parallel mode 0.7643.
  • Comparing two runs. Shares of templates are computed from the number of records in each run, so different log sizes do not matter. A template counts as changed when its share grew or fell by at least a factor of 2 and it has at least 10 records in either run (both thresholds are configurable). Identical inputs give an empty result.
  • Exit code for CI. --fail-on-new exits with code 2 when there are new templates, --fail-on-new-alerts when any of them is WARN, ERROR or FATAL. A reworded message that the default matcher pairs with an old one counts as changed, not new; --matcher exact makes the gate strict.
  • Memory. The file is read as a stream, and memory use does not depend on its size. Inputs: files, gzip, standard input, several files as one run.
  • Parallelism. A large file is cut into chunks (64 MiB by default) and the chunk trees are merged in order. For a fixed chunk size the result does not depend on the number of threads. The strategy is chosen automatically: a large file is mined in parallel, and sequentially when the first chunk shows that almost every line is a new message (--strategy auto, the default). --warm-start starts every chunk from the tree of the first one: far fewer stray templates, at the price of mining the first chunk alone.
  • Value masks. By default UUIDs, timestamps, IPs, hex values, paths and numbers are replaced; the rules can be changed.
  • Reports. HTML (one file, no network requests, strict CSP), JSON with a versioned schema, text, Markdown, CSV. A report includes raw example lines by default; --examples masked or none removes them.
  • Extensions. Log formats, reports and template matchers for diff are plugins, loaded through entry points or from a folder of .py files.

Install

pip install "logfold[cli]"

Python 3.10 or newer. PyPI has prebuilt packages for Linux (x86_64, aarch64, musl), macOS (x86_64, arm64) and Windows (x86_64), so pip installs without compiling and you do not need Rust. On any other platform pip builds the package from source, which needs a Rust compiler. Without [cli] you get the library only.

Quick start

Analyze a log:

logfold analyze app.log --top 30 --out report.html

The format is detected from a sample of the file (nginx, apache, syslog, journald, Kubernetes, JSON lines, logfmt and others). If it is not sure, the command lists the candidates and asks you to pass --format. Indented stack-trace lines are joined to the record that started them.

Compare two runs:

logfold diff before.log after.log --out diff.html --fail-on-new-alerts

Exit codes: 0 success, 1 error, 2 something requested by a --fail-on-* flag was found.

Compare saved results without reading the logs again:

logfold analyze before.log --out before.json
logfold analyze after.log  --out after.json
logfold diff before.json after.json

A JSON file written with --out holds every template, so it is suitable for this kind of comparison.

From Python

from logfold import analyze, diff, load_analysis

result = analyze("app.log")  # the format is detected
for template in result.top(10):
    print(template.count, template.level, template.text)
result.to_html("report.html")

comparison = diff("before.log", "after.log")
comparison.new_templates
comparison.new_alerts  # new WARN/ERROR/FATAL templates
comparison.to_html("diff.html")

# compare saved results
diff(load_analysis("before.json"), load_analysis("after.json"))

analyze() and diff() return immutable dataclass objects.

Formats and parameters

Formats nginx, apache, nginx-error, syslog, journald, k8s (CRI/containerd), jsonl, app (<time> LEVEL message), logfmt, serilog-clef, plain, your own regex:<pattern>. List: logfold formats.
Multi-line records --multiline; with --format auto it turns on by itself when indented lines are found.
Folding --depth (4), --sim-th (0.4), --max-children (100), --max-templates (100000). The defaults are the same as in Drain3.
Execution --strategy auto (default; parallel chunks, sequential for logs of unique messages), sequential, chunked; --threads, --chunk-mb; --warm-start (opt-in, chunked only).
Logs with almost unique lines --high-cardinality: at most 5000 templates, the rest go into catch-all templates, runs sequentially. On a 10 MB file with 84 thousand distinct lines 2.0 s becomes 0.14 s.
Reports HTML, JSON, text, Markdown, CSV; the --out suffix picks the format, --report NAME picks the report explicitly, including one from a plugin.
Matchers for diff jaccard (default), token_subset, exact: they link a reworded message to its earlier version so it is not counted as both new and gone.
Plugins logfold plugins list, check, install, new.
Scripting --json prints JSON to stdout, exit codes are stable, the JSON format is described by a schema in docs/schema.

Speed

Measured on one machine (8 cores, Windows 11); the protocol was fixed before the runs, details and data are in bench/RESULTS.md.

logfold, 16 threads Drain3 (Python)
nginx access log, 100 MB 0.38 s 5.26 s
application log, 100 MB 0.41 s 9.03 s
nginx access log with value masking 0.45 s 26.82 s
HDFS, 1.57 GB, a real log 0.94 s not measured
diff of two 100 MB logs 0.7 s no diff

On the real logs of 0.7 to 1.6 GB peak memory is 42 to 51 MB with one thread and 107 to 129 MB with 16 threads.

Limitations

Warning. Keep these in mind before running logfold on large logs and comparing results.

  • Speed was measured on Windows 11 only; on Linux and macOS correctness is tested, but speed is not.
  • The parallel mode builds a tree per chunk and merges them, so on logs without masks it can return more templates than the sequential mode (HDFS without masks: 341 against 43; --warm-start brings it to 45 at the cost of a serial first chunk). On logs with a very large number of distinct messages the default auto strategy notices that after the first chunk and mines sequentially; --high-cardinality makes it faster still.
  • Saved results are compared without a recount against a shared template tree, so the same event can end up both in new and in gone; the matcher (jaccard by default) exists for this.

Measurements and bug reports

logfold was measured on one machine (Windows 11, 8 cores). If you can run it on other hardware (Linux, macOS, ARM, a slower disk, more cores) or on your own logs, we would be glad to get the numbers. We also want to hear about wrong results, crashes, templates that are grouped badly, and runs that are slow or use too much memory.

  • Measurements. Run the benchmark as described in bench/README.md (the protocol is in bench/PROTOCOL.md) or time your own command, and open a performance issue. Include the wall time, throughput and peak memory, the command, the size and format of the input, the CPU and number of cores, RAM, disk type, OS, the logfold version and the number of threads.
  • Bugs. Open a bug report with what you expected and what happened, a command or Python snippet that reproduces it, the output of logfold --version and logfold info, and a few lines of the input with secrets removed.

All issue forms are listed on the new issue page; how issues are written is described in CONTRIBUTING.md.

How it compares to other tools

logfold Drain3 logdrain logdelta
Language Rust core, Python API and CLI Python Rust Rust
Template quality same as Drain3 on Loghub-2k reference Drain Drain-based
Comparing two runs yes (diff, shares normalized, recount) no no (online "template created" signal) yes (diff, several baselines, blocks)
Python API yes yes no no
Multi-threaded mining of one big file yes, deterministic no not documented for the CLI not documented
Reports JSON, HTML, text, Markdown, CSV - text, JSON, CSV terminal, JSON, Markdown

Template quality: python eval/quality.py (grouping accuracy on the 16 Loghub-2k datasets).

Documentation

Design

A pure core (masking, tokenizer, Drain-compatible tree, merge) with no I/O, adapters for files and formats, an execution layer, a thin PyO3 shim, and a Python package on top. The algorithm is described in docs/ALGORITHM.md. A pure-Python reference engine implements the same specification, and the Rust engine is tested against it for exactly equal results.

Development

Rules for branches, commits and the definition of done are in CONTRIBUTING.md. Report vulnerabilities privately, see SECURITY.md.

License

MIT, see LICENSE. Copyright (c) 2026 Andrey Kilanov.

Metadata

Release files for logfold 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logfold 0.3.0
File Size Uploaded
logfold-0.3.0.tar.gz 129.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for logfold 0.3.0
File
logfold-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
logfold-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
logfold-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
logfold-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
logfold-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
logfold-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 8.3 MB

Release files / logfold-0.3.0.tar.gz

Download URL logfold-0.3.0.tar.gz
Size 129.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b9ee8b4607141fe26bef5c45caca59fc4dbbf4f0cbde88a08cda279c11100f0a
BLAKE2b-256 checksum
How to use checksums
da04e92180cf5d132b87da8dafe3033f1f8d5b2630c1852016e1c6e03483f859
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / logfold-0.3.0-cp310-abi3-win_amd64.whl

Download URL logfold-0.3.0-cp310-abi3-win_amd64.whl
Size 1.3 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
63248081a1b0e3db75aab1ca5bf441f8fbc365751fbcd848f5b31c155bf6f2b8
BLAKE2b-256 checksum
How to use checksums
a9d8b2143b8f4a7811a077fe58d612409fb43a4d0b3d9bb0231f927c32c9bdc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / logfold-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL logfold-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
1fd5b8ad28e4a5b99f9c84733c60524cec6ab5b347ed9bd1eaf8d9735122fef8
BLAKE2b-256 checksum
How to use checksums
3577c1849bca662175ff234f057a1d3bf72f3116d6f14a88a3403588af4f5406
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / logfold-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL logfold-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
fab3fa3ae0a3718a3234db14e09fbf825852ceed44c5d4f1ac655311b2345eb0
BLAKE2b-256 checksum
How to use checksums
ed4d95de9050970cf52096b006104532f77ef637ce5338307ef4720522ed4e8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / logfold-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL logfold-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e2ed8d9dece21590a084e229f012072101a86912e89a1bf534c8c4214f7fbfa3
BLAKE2b-256 checksum
How to use checksums
d22b755ae535e09b40c0c042cf313a91cc9d9aa2f1b54a3210efc399d8757935
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / logfold-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL logfold-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.2 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
620d382c5478970ef81f7927970e85bac4c78c467e5be0e047e38e210a96d526
BLAKE2b-256 checksum
How to use checksums
69263b5679de2201b488fefb194e372c9ffef0d738ba9ad3769fcad7e8bf1471
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / logfold-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL logfold-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
5eff61c355df3169216117a8ee93d57dc1d38df6dc4781aa59e3e86eb83a0436
BLAKE2b-256 checksum
How to use checksums
35eac99d835188721c63f736c5a56f0087613c63d77cd9101ae928fdfe7d6a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.0

7 release files

0.4.0

7 release files

This release

0.3.0 This release

7 release files

0.2.1

7 release files

0.2.0

7 release files

0.1.0

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page