Skip to content

feat: add nyanpasu-log-preview for bounded payload logs - #206

Merged
greenhat616 merged 2 commits into
mainfrom
feat/log-preview
Oct 22, 2026
Merged

greenhat616 merged 2 commits into
mainfrom
feat/log-preview

Conversation

@greenhat616

@greenhat616 greenhat616 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Logging an image, a profile or a script with Debug prints every byte of it. In the app, a statistic widget's image logo alone becomes about a megabyte of text per log line.

  • nyanpasu-log-preview (new crate in log-preview/): formats a payload as its length, CRC-32 and a configurable number of bytes from each end.

    • bytes(&[u8]) writes the ends in hex; text(&str) writes them as escaped strings and never splits a character.
    • .edge(n) sets how many bytes each end shows (default 8). A payload no longer than both ends is shown whole.
    • Display and Debug are the same, so it fits both % and ? fields in tracing.
    262144 bytes, crc32 67d38fb2, 89504e470d0a1a0a..49454e44ae426082
    40 bytes, crc32 fa887ff7, "function".."onfig; }"
    
  • It is a separate path crate that depends only on crc32fast, so the widget protocol (used by the Tokio-free widget process) can use it without pulling in Tokio. It is not a workspace member, which keeps this repository free of a nested workspace; inside nyanpasu-runtime it becomes a workspace member automatically. nyanpasu-utils re-exports it as log_preview.

  • parse_check_output was instrumented without skipping its argument, so a failed config check recorded the core's whole stdout as a span field. It now records a preview. Only the legacy CoreInstance calls it, so no current app or service path reaches it.

Notes

  • The standalone Cargo.lock gains crc32fast and the new crate. Cargo also re-resolved a few windows-sys 0.59 references to 0.61; both satisfy the declared ranges.
  • cargo package would need a version on the new path dependency. The crate is already unpublishable because of the git ProcessKit dependency, so no version was added.

Test plan

  • cargo test -p nyanpasu-log-preview: 7 unit tests and 1 doctest. They cover short payloads, both ends, zero and usize::MAX edges, exactly two edges, character boundaries, and Debug = Display.
  • cargo clippy -p nyanpasu-utils --all-features --all-targets: no new warnings. The process/engine.rs warning was already there.

Consumers: libnyanpasu/nyanpasu-runtime#458 (pin bump) and libnyanpasu/clash-nyanpasu#5941 (app log points).

Logging an image, a profile or a script with Debug prints every byte:
a widget logo alone becomes about a megabyte of text per line. The new
crate formats a payload as its length, CRC-32 and a configurable number
of bytes from each end, through both Display and Debug.

It is a separate path crate that depends only on crc32fast, so the
statistic widget's protocol can use it without pulling in Tokio.
nyanpasu-utils re-exports it as log_preview.
parse_check_output was instrumented without skipping its argument, so a
failed config check recorded the core's whole stdout as a span field. It
now records the output's length, CRC-32 and ends.
@semanticdiff-com

semanticdiff-com Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  Cargo.lock Unsupported file format
  Cargo.toml Unsupported file format
  README.md Unsupported file format
  log-preview/Cargo.toml Unsupported file format
  log-preview/src/lib.rs  0% smaller
  src/core/utils.rs  0% smaller
  src/lib.rs  0% smaller

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant