>_EXECUTIVE SUMMARY
zcolorizer v0.2.3 is a single-crate Rust workspace (~3,855 lines across 10 source files) that ports ccze and the pygments regex→token idea. The pipeline is three decoupled pieces: rules tag spans of a line with semantic tokens, a theme maps each token to a style, and the engine paints the claimed spans. It ships a library (rlib + staticlib + cdylib) and a CLI binary, with the clap dependency confined to the CLI behind the default cli feature.
~MODULE MAP
The crate is organized around the rules → theme → engine pipeline. The two module files (modules.rs + modules_modern.rs) carry the bulk of the format ports, while theme.rs holds the 32 builtin palettes. Bar widths are relative to the largest file.
| Source | Lines | Size | Role |
|---|---|---|---|
src/lib.rs | 60 | Crate root and public API; documents the rules → theme → engine pipeline. | |
src/rules.rs | 257 | RuleDef/Rule: regex→token rules — named-group rules (group name is the token) and whole-match rules. | |
src/theme.rs | 517 | Token→Style themes; 31 cyberpunk palettes plus ccze-classic (32 builtins), neon-sprawl default. | |
src/color.rs | 386 | Color (16 named / 256-index / truecolor RGB) and Style, with ANSI SGR rendering. | |
src/engine.rs | 405 | Colorizer: runs compiled rules over each line; first rule to claim a byte owns it, mirroring ccze's module-then-wordcolor flow. | |
src/config.rs | 363 | TOML config — merges theme, rules and module selections; XDG config path resolution. | |
src/modules.rs | 622 | Module type plus 20 classic ccze plugin ports (syslog, httpd, squid, dpkg, postfix, exim, ftp, php, ulogd…). | |
src/modules_modern.rs | 635 | 27 modern format modules: journald, authlog, kernel, nginx, haproxy, JSON/logfmt, postgres/mysql/redis/mongodb, docker/klog, fail2ban/ufw… | |
src/error.rs | 32 | Crate Error enum (thiserror): bad-rule regex, unknown theme, config/IO errors. | |
src/bin/zcolorizer.rs | 578 | CLI binary (clap): streaming stdin/file colorization, theme/module/rule listing, config dump. | |
| 10 files | 3,855 | Library (rlib + staticlib + cdylib) plus the cli-feature binary. |
~ARCHITECTURE
Three independently editable pieces — change one without disturbing the others. Because color lives entirely in the theme, switching themes recolors every log without touching a single rule.
Rules
A rule is a regex whose named capture groups are tokens — one pattern can paint several fields (date, host, error). Whole-match rules use an explicit token. Fully editable in the TOML config.
Themes
A token→Style map you swap live. 31 cyberpunk palettes plus ccze-classic (32 builtins), default neon-sprawl. Colors are truecolor RGB, 256-index, or named ANSI.
Engine
Colorizer runs the compiled rules over each line; the first rule to claim a byte owns it, mirroring ccze's module-then-wordcolor flow. Streams line-buffered so tail -f / journalctl -f stay live.
~DEPENDENCY FOOTPRINT
Eight direct dependencies, all foundational and durable; clap is optional and CLI-only. All are dual-licensed MIT OR Apache-2.0, matching zcolorizer's own MIT license. The vendored ccze C source is a build-time reference only and is excluded from the published crate — the Rust port is original.
| Crate | Ver | License | Why |
|---|---|---|---|
| serde | 1 | MIT / Apache-2.0 | Derive (de)serialization for config, themes, rules. |
| serde_json | 1 | MIT / Apache-2.0 | --themes-json emit for tooling. |
| toml | 0.8 | MIT / Apache-2.0 | Parse/emit the on-disk config and --dump-config. |
| regex | 1 | MIT / Apache-2.0 | Compiles the rule patterns that tag tokens. |
| thiserror | 2 | MIT / Apache-2.0 | Derives the crate error type. |
| dirs | 6 | MIT / Apache-2.0 | Resolves the XDG config directory. |
| once_cell | 1 | MIT / Apache-2.0 | Lazily-initialized builtin tables. |
| clap (optional) | 4 | MIT / Apache-2.0 | CLI argument parsing — only under the cli feature; the library never depends on it. |
~VERIFICATION
108 tests in total: 91 unit tests embedded across the source modules plus 17 integration tests in tests/integration.rs. The integration suite drives the real colorizer through tagging assertions — verifying that syslog/httpd/squid/dpkg/postfix/exim/php/vsftpd modules paint the correct fields, that swapping a theme changes color without changing structure, that the generic word-colorizer assigns distinct tokens to good/bad word lists, that replace-mode uses only user rules, that multi-line input colorizes each line, and that config round-trips through TOML. Release profile builds with LTO and symbol stripping. Run with cargo test.
| Suite | Tests | Scope |
|---|---|---|
| engine | 21 | Rule application, span claiming, line painting. |
| config | 19 | TOML merge, theme/rule/module selection, round-trip. |
| color | 14 | Named / 256-index / truecolor parsing and ANSI SGR. |
| theme | 14 | Builtin palettes, token→style lookup, defaults. |
| modules | 11 | Classic ccze plugin ports. |
| rules | 10 | Named-group and whole-match rule definitions. |
| modules_modern | 2 | Modern format module ports. |
| tests/integration.rs | 17 | End-to-end tagging assertions across modules + themes. |
| Total | 108 | 91 unit + 17 integration. |
~PROVENANCE
The Rust port is original; no GPL code ships in the published crate.
Upstream
Ported from ccze and the pygments regex→token idea. The vendored ccze C source is a build-time reference only and is excluded from the published crate.
Distribution
Ships as a library (rlib + staticlib + cdylib) and a CLI binary. Available on crates.io (cargo install zcolorizer) with API docs on docs.rs.
License
MIT. All eight direct dependencies are dual-licensed MIT OR Apache-2.0, matching the crate's own license.