Skip to content

Fix: log-system follow-ups for #703#706

Merged
ChaoWao merged 1 commit intohw-native-sys:mainfrom
ChaoWao:fix/log-system-followup
Apr 30, 2026
Merged

Fix: log-system follow-ups for #703#706
ChaoWao merged 1 commit intohw-native-sys:mainfrom
ChaoWao:fix/log-system-followup

Conversation

@ChaoWao
Copy link
Copy Markdown
Collaborator

@ChaoWao ChaoWao commented Apr 30, 2026

Summary

Three follow-up issues found post-merge of #703 (the V0..V9 log redesign).

1. pytest --log-level v0 was broken

pytest's CLI validator does:

int(getattr(logging, level.upper(), level))

so accepted level names must be module attributes on logginglogging.addLevelName alone is insufficient. addLevelName only registers _levelToName / _nameToLevel dicts, which pytest doesn't consult here.

Fix: also setattr(logging, "V0", 15) ... setattr(logging, "V9", 24) plus setattr(logging, "NUL", 60) and setattr(logging, "NULL", 60) (pytest upcases nullNULL before lookup). Done in two places:

  • python/simpler/_log.py — for the standalone python test_*.py --log-level v3 path that goes through argparse after import simpler.
  • conftest.py top-level — pytest validates the CLI value before conftest's first import simpler, so the module-level registration there is the one that actually saves pytest. The two registrations are redundant by design.

The addLevelName calls are kept for the side-benefit: %(levelname)s formatters now print V3 instead of Level 18.

2. L3/L4 chip subprocesses ignored the simpler logger

Worker.init() correctly snapshotted Python's simpler logger and forwarded it through ChipWorker.init(..., log_level, log_info_v) for the L2 path. The L3/L4 fork loops (_chip_process_loop and _chip_process_loop_with_bootstrap) called ChipWorker.init(...) without the new args, so each subprocess started its HostLogger / AICPU at the binding default (V5/INFO) regardless of what the user had configured.

Fix: added log_level / log_info_v parameters to both child loops (defaulted to 1, 5 for safety), and snapshot the parent's logger config once before the fork loop in _start_hierarchical — explicitly forwarded to each child invocation. After fork the child can't read the parent's logger state, so values must travel through the call site.

3. docs/testing.md was stale

The "Configuration sources" paragraph still described the C2-era model where Worker.run() snapshots into CallConfig.log_level per-task. Those CallConfig fields were dropped in C4; the snapshot is now one-shot at Worker.init(). Rewrote the paragraph and the Option Reference row to match the actual implementation, and documented the L3/L4 fork plumbing.

Test plan

  • pytest --log-level v0/v3/v9/info/warn/error/null/debug all accepted (8 variants × 11 cases pass)
  • cpput: 21/21
  • py UT: 210/210 (excluding torch-only)
  • Hardware st-onboard-* and CI to be exercised in PR CI

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the logging infrastructure to support custom verbosity levels (V0-V9 and NUL) by registering them as attributes on the logging module for pytest compatibility. It also modifies worker initialization to snapshot and pass logging levels explicitly to forked child processes. Documentation was updated to describe these changes, and feedback was provided to clarify the technical requirements for pytest compatibility within the docs.

Comment thread docs/testing.md Outdated
Three issues reported after hw-native-sys#703 merged:

1. `pytest --log-level v0` was rejected ("'V0' is not recognized as a
   logging level name"). pytest's CLI validator uses
   `int(getattr(logging, name.upper(), name))`, so the level names must be
   exposed as **attributes on the logging module** — `logging.addLevelName`
   alone is not enough. Set both: keep `addLevelName` for nice
   `%(levelname)s` formatting, and `setattr(logging, ...)` so pytest's
   getattr lookup resolves. Mirror the registration in conftest.py top-level
   too — pytest validates --log-level before conftest's first `import
   simpler`. Also expose `logging.NULL` for `pytest --log-level null`
   (pytest upcases the value before lookup).

2. L3/L4 chip subprocesses ignored the user's simpler logger level. The
   parent's `Worker.init()` snapshot was only forwarded along the L2 path;
   `_chip_process_loop` and `_chip_process_loop_with_bootstrap` called
   `ChipWorker.init()` with the binding defaults (V5/INFO). Added
   `log_level` / `log_info_v` parameters to both child loops and snapshot
   the parent's logger config once before the fork loop in
   `_start_hierarchical`, then pass it explicitly into each forked child.

3. `docs/testing.md` Configuration Sources paragraph still claimed
   `Worker.run()` snapshots into `CallConfig.log_level` / `log_info_v`
   per-run. Those CallConfig fields were dropped in C4; the actual snapshot
   is one-shot at `Worker.init()`. Rewrote the paragraph to match,
   documented the L3/L4 fork plumbing, and updated the
   `--log-level` row in the Option Reference.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ChaoWao ChaoWao force-pushed the fix/log-system-followup branch from 2a1976d to 833369d Compare April 30, 2026 06:37
@ChaoWao ChaoWao merged commit 5029466 into hw-native-sys:main Apr 30, 2026
14 checks passed
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