Skip to content

chore: convert generators (generate_patt + nft_marker_gen) to arlog_*! (PR 3/4 for #90)#122

Open
maxwelljhuang wants to merge 2 commits into
webarkit:devfrom
maxwelljhuang:chore/arlog-examples-pr3-generators
Open

chore: convert generators (generate_patt + nft_marker_gen) to arlog_*! (PR 3/4 for #90)#122
maxwelljhuang wants to merge 2 commits into
webarkit:devfrom
maxwelljhuang:chore/arlog-examples-pr3-generators

Conversation

@maxwelljhuang
Copy link
Copy Markdown
Contributor

Part 3 of 4 for #90 . Converts the two generator CLI examples to the project's arlog_*! macros. PR 3 is larger than PR 1 or PR 2 (84 print sites combined) and exercises arlog_e! and arlog_w! in examples/ for the first time, plus introduces three "do-not-convert" categories: CLI help banners, interactive prompts, and empty spacers. Calling out the contestable judgments up front so review can focus there.

Scope

  • crates/core/examples/generate_patt.rs — 716 lines, 34 print sites: 16 help-banner eprintln! kept, 16 → arlog_i!, 1 → arlog_w!, 1 → arlog_e!. Logger init + imports added.
  • crates/core/examples/nft_marker_gen.rs — 399 lines, 50 print sites: 6 y/N prompt sites kept, 10 empty spacers deleted, 25 → arlog_i!, 7 → arlog_e!, 2 → arlog_w!. Logger init was already present from a prior change; imports added.
  • crates/core/Cargo.toml — new [[example]] block for generate_patt with required-features = ["log-helpers"]. nft_marker_gen's block already exists.

Categorical decisions

CLI help banner stays as eprintln! (16 sites in generate_patt.rs print_help_and_exit). Routing --help output through arlog_i! would prefix every line with [info] and apply level filtering — wrong UX for help text, which is human UI not log events.

Interactive y/N prompt stays as eprintln!/eprint! (6 sites in nft_marker_gen.rs). The prompt + read_line block needs synchronous stderr output that a log facade can't guarantee.

Empty println!(); spacer lines deleted rather than converted (10 sites in nft_marker_gen.rs). An empty arlog_i!() renders as a bare [info] with no body, which is noise. The spacing was a stdout-style artifact from the original C markerCreator. Happy to preserve them in some other form (e.g. arlog_i!("") to maintain visual structure) if you'd prefer — let me know.

if cfg.debug / if cfg.verbose wrappers in generate_patt.rs preserved, inner calls converted to arlog_i! with "Debug:"/"Verbose:" prefixes intact. Two cleaner alternatives exist:

  • (b) wire cfg.debug/verbose to set_ar_log_level() at startup, drop wrappers, use arlog_d!. Behavior-preserving but introduces global state coupling and would unmute any arlog_d! in linked library code.
  • (c) drop the CLI flags entirely, use arlog_d!, document RUST_LOG=debug. Cleanest semantics, but a user-visible CLI surface change.

Defaulting to (a) for minimum-change. Happy to flip to (b) or (c) — both are reasonable, and (c) might be the right long-term answer; let me know your preference and I'll push a fixup or open a follow-up.

Sub-classification: lines 328, 341, 347 in nft_marker_gen.rs are three per-scale outcomes in the FREAK feature loop, classified differently. 328 (arlog_i!) is success, 341 (arlog_i!) is an expected skip for small scales, 347 (arlog_w!) is an unexpected per-scale failure where the loop continues. Following the existing author's signal (println vs eprintln) for which is which.

small adjustment beyond the plan

use webarkitlib_rs::arlog_w; in nft_marker_gen.rs is gated on #[cfg(feature = "ffi-backend")] to silence an unused-import warning on the no-ffi build. Both arlog_w! call sites are already inside that cfg block; the import follows them.

Verification

  • cargo fmt --all -- --check ✓
  • cargo build --example generate_patt --features log-helpers ✓
  • cargo build --example nft_marker_gen --features log-helpers ✓
  • cargo clippy --features log-helpers — no new lints in either touched file
  • cargo test ✓
  • cargo run --example generate_patt --features log-helpers -- --help ✓ — confirmed plain text output, no [info] prefixes (Q1 verified)
  • cargo run --example generate_patt --features log-helpers ✓ — confirmed [info] arlog output on the converted paths
  • cargo run --example nft_marker_gen --features log-helpers (with -y to skip the y/N prompt) ✓
  • grep for residual print calls — only the 16 help-banner sites and 6 y/N prompt sites remain, as planned

Skipped per pre-existing issues already documented on the issue thread: cargo build --all-features (macOS stdc++ link issue) and cargo clippy --all-targets -- -D warnings (lib-side doctest lint in arlog.rs:299).

Followups

  • PR 4: simple_nft.rs (depends on ffi-backend feature, kept separate so reviewers without an FFI setup could sign off on PRs 1–3 independently).

Converts println!/eprintln!/eprint! in the two generator examples to the
project arlog_*! macros, plus adds a [[example]] block for generate_patt
in Cargo.toml.

generate_patt.rs (716 lines, 34 print sites):
- 16 help-banner eprintln! kept as-is (CLI UI, not log events)
- 1 unknown-arg eprintln! -> arlog_w! (recoverable, parse continues)
- 1 top-level Err eprintln! -> arlog_e!
- 16 -> arlog_i! (success reports, setup info, debug/verbose-gated lines)
- The if cfg.debug / if cfg.verbose wrappers and the --debug / --verbose
  CLI flags are preserved unchanged; only the inner eprintln! calls
  routed through arlog_i! with "Debug:"/"Verbose:" prefixes intact.
  Decoupling the flags from arlog levels would be a user-visible CLI
  change and is left to a separate PR.

nft_marker_gen.rs (399 lines, 50 print sites):
- 6 y/N prompt eprintln!/eprint! kept as-is (interactive UI)
- 10 empty println!() spacer lines deleted (would render as bare
  [info] noise; original spacing was a stdout-style artifact)
- 7 error-and-exit eprintln! -> arlog_e!
- 2 recoverable eprintln! -> arlog_w! (per-scale failure, no-features
  warning), gated import follows since both sites are inside the
  ffi-backend cfg block
- 25 -> arlog_i! including bounded enumeration loops over scales,
  matching the debug_labeling.rs:92-97 / load_nft.rs precedent

Cargo.toml: new [[example]] block for generate_patt with
required-features = ["log-helpers"], placed in the *_patt cluster.

Verified --help renders plain text (no [info] prefixes) and single
runs of both generators show correctly prefixed arlog output.

Part 3 of 4 for webarkit#90.
@kalwalt kalwalt changed the base branch from main to dev May 11, 2026 05:39
@kalwalt
Copy link
Copy Markdown
Member

kalwalt commented May 11, 2026

Thank you for this PR! 🙌🔝 i will review It this afternoon.

@kalwalt kalwalt added enhancement New feature or request rust code examples labels May 11, 2026
*/

fn print_help_and_exit() {
eprintln!("generate_patt example — usage:");
Copy link
Copy Markdown
Member

@kalwalt kalwalt May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the arlog_rel here and in the lines after this code printing, it will not print the [info] pre text or other type of header.

use std::io::Write as _;
if !cli.yes {
eprintln!();
eprintln!(
Copy link
Copy Markdown
Member

@kalwalt kalwalt May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i said for the generate_patt.rs you can use arlog_rel here. Don not appyly to this line eprint!("Continue anyway? [y/N] "); i'm not sure that arlog_rel can works.

Copy link
Copy Markdown
Member

@kalwalt kalwalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments in the code, if you can apply the changes requested. After that i will merge it.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants