Repository navigation
refactor(log): unify FL_WARN/FL_WARN_F via argument-count dispatch (#3272) - #3273
Conversation
…3272) One FL_WARN(...) macro now accepts BOTH stream-style and printf-style: FL_WARN("plain literal") // 1 arg → stream form FL_WARN("foo " << x << " bar") // 1 arg → stream form FL_WARN("got %d items", n) // 2 args → printf form Macro-level dispatch (via the classic PP_NARG / picker-list trick) routes single-arg calls to the existing sstream/log_emit path and two-or-more-arg calls to the existing log_emit_f path. The same treatment is applied to FL_ERROR, FL_INFO, FL_PRINT, FL_LOG_ASYNC, and the per-channel FL_LOG_* family plus their ASYNC_MAIN variants. All `_F` macros are preserved as one-line aliases for backward compatibility, so every existing call site of FL_WARN(X), FL_WARN_F(fmt, args), FL_ERROR_F, FL_PRINT_F, FL_LOG_*_F, and FL_LOG_*_ASYNC_MAIN_F keeps compiling unchanged. New code should drop the _F suffix. Closes #3272. Notes: - Disabled-platform no-ops (FASTLED_LOG_VERBOSITY=0 / !SKETCH_HAS_LARGE_MEMORY) expand to true `do { } while(0)`. This drops the compile-time sstream_noop type-check that the old FL_WARN_IF carried — that check was only on _IF (inconsistent with FL_WARN / FL_WARN_F / FL_WARN_F_IF / per-channel _F variants, which were already true no-ops) and an early draft of this patch revealed it would force evaluation of args declared only under FASTLED_LOG_*_ENABLED (e.g. parlio_buffer_calc.h:238). - This change does NOT migrate any call sites and does NOT shrink the binary. The ~5-10 KB ESP32-S3 saving stays scoped to #3158, which can now build on this unified entry point. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesUnified Logging Macro Dispatch
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/fl/log/log.hpp (1)
470-480: ⚡ Quick winAdd
FL_INFO_F(andFL_INFO_F_IF) alias compile-path coverage.This suite validates
_Faliases for WARN/ERROR/PRINT but not INFO. Since this PR adds/keeps unified alias behavior, adding INFO alias checks here closes a small coverage gap.Suggested test additions
FL_TEST_CASE("FL_INFO unified - printf-style") { FL_SUBCASE("FL_INFO with printf format") { FL_INFO("info: %d", 123); FL_CHECK(true); } FL_SUBCASE("FL_INFO with stream chain") { FL_INFO("info " << 456); FL_CHECK(true); } + + FL_SUBCASE("FL_INFO_F alias still compiles") { + FL_INFO_F("legacy info: %d", 321); + FL_CHECK(true); + } } + +FL_TEST_CASE("FL_INFO_IF unified - printf-style") { + FL_SUBCASE("FL_INFO_F_IF alias still compiles") { + FL_INFO_F_IF(true, "conditional info: %d", 9); + FL_CHECK(true); + } +}Based on learnings from the PR objectives, unified API behavior explicitly includes
_Falias compatibility and this test layer is intended to validate those compile paths.Also applies to: 499-509
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/fl/log/log.hpp` around lines 470 - 480, The test case "FL_INFO unified — printf-style" is missing test coverage for the FL_INFO_F and FL_INFO_F_IF macro aliases that are validated for other logging levels like WARN, ERROR, and PRINT. Add FL_SUBCASE entries to test both FL_INFO_F with printf-style formatting (e.g., FL_INFO_F("info: %d", 123)) and FL_INFO_F_IF with a conditional variant to match the pattern used for validating the _F aliases in other logging macros and complete the compile-path coverage for unified alias behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/fl/log/log.hpp`:
- Around line 420-423: The file contains Unicode em dashes (—) in comment block
delimiters on lines 420, 425, 451, 470, 482, and 499 that violate the 7-bit
ASCII only character set requirement for C++ source files. Locate each
occurrence of the Unicode em dash character in these lines and replace it with a
regular ASCII hyphen (-) character to ensure compliance with the repository's
coding guidelines for source file character encoding.
---
Nitpick comments:
In `@tests/fl/log/log.hpp`:
- Around line 470-480: The test case "FL_INFO unified — printf-style" is missing
test coverage for the FL_INFO_F and FL_INFO_F_IF macro aliases that are
validated for other logging levels like WARN, ERROR, and PRINT. Add FL_SUBCASE
entries to test both FL_INFO_F with printf-style formatting (e.g.,
FL_INFO_F("info: %d", 123)) and FL_INFO_F_IF with a conditional variant to match
the pattern used for validating the _F aliases in other logging macros and
complete the compile-path coverage for unified alias behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0f7b5faa-96c4-4cfe-be1b-923f934fa8b1
📒 Files selected for processing (2)
src/fl/log/log.htests/fl/log/log.hpp
- Drop newly-introduced FL_INFO_F / FL_INFO_F_IF aliases. Master never had
them; the unified FL_INFO already accepts both stream- and printf-style,
so the _F suffix adds API surface for no benefit. Per author direction,
new code should call FL_INFO("fmt %d", x) directly.
- Replace remaining non-ASCII characters (em dash, right-arrow) introduced
by this PR with ASCII equivalents (`-`, `->`) to satisfy the 7-bit
ASCII source-file rule. The pre-existing `×` on log.h:168 (not part
of this PR) is left untouched.
- Expand FL_INFO test coverage to mirror WARN/ERROR/PRINT: add FL_INFO_IF
printf-style and stream-style subcases.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Closes #3272.
One
FL_WARN(...)macro now accepts BOTH stream-style and printf-style call sites — no more_Fsuffix needed in new code. Macro-level argument-count dispatch routes single-arg calls to the existing sstream/log_emitpath and two-or-more-arg calls to the existinglog_emit_fpath.```cpp
FL_WARN("plain literal"); // 1 arg → stream form (sstream/log_emit)
FL_WARN("foo " << x << " bar"); // 1 arg → stream form
FL_WARN("got %d items", n); // 2 args → printf form (log_emit_f)
```
The same treatment applies to
FL_ERROR,FL_INFO,FL_PRINT,FL_LOG_ASYNC, the per-channelFL_LOG_*family, and the per-channelFL_LOG_*_ASYNC_MAINfamily.Backward compatibility
All
_Fmacros are preserved as one-line aliases. Every existing call site ofFL_WARN(X),FL_WARN_F(fmt, args),FL_ERROR_F,FL_PRINT_F,FL_LOG_SPI_F,FL_LOG_RMT_F, etc. compiles unchanged. New code should drop the_Fsuffix.Non-goals
This change does NOT migrate any call sites and does NOT shrink the binary. The ~5–10 KB ESP32-S3 saving stays scoped to #3158, which can now build on this unified entry point.
Notes
FASTLED_LOG_VERBOSITY=0or!SKETCH_HAS_LARGE_MEMORY, all macros now expand to truedo { } while(0). This drops the compile-timesstream_nooptype-check that the oldFL_WARN_IFcarried. That check was only on_IF(inconsistent withFL_WARN/FL_WARN_F/FL_WARN_F_IFand all per-channel_Fvariants, which were already true no-ops). An early draft of this patch tried to preserve and unify the type-check, but it forced evaluation of args declared only underFASTLED_LOG_*_ENABLED(e.g.parlio_buffer_calc.h:238'suncappedCapacity) and broke the build.FL_INFO_F,FL_INFO_F_IFare net-new aliases (master had no printf form forFL_INFO).Implementation
A small
_FL_VA_PICK17macro + filler list picks_S(single-arg stream helper) when the user passes 1 arg and_M(multi-arg printf helper) for 2..16 args. The picker is shared across all FL_WARN/FL_ERROR/FL_INFO/FL_PRINT/FL_LOG_ASYNC families via per-kind_FL_<KIND>_S/_FL_<KIND>_Mhelpers.Macro-level dispatch (rather than C++ function-overload resolution) is required because the single-arg stream form is a chained
<<expression — it only compiles when the macro injectsfl::sstream()as the LHS. Routing through a function call would force the<<chain to evaluate standalone, which fails (const char*has nooperator<<(float)).Test plan
bash test --cpp— 331/331 passedbash lint— cleantests/fl/log/log.hppverify both stream and printf forms of FL_WARN/FL_ERROR/FL_INFO/FL_PRINT/FL_WARN_IF, plusFL_WARN_F/FL_ERROR_F/FL_PRINT_Faliases.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests