Skip to content

refactor(log): unify FL_WARN/FL_WARN_F via argument-count dispatch (#3272) - #3273

Merged
zackees merged 2 commits into
masterfrom
feat/3272-unify-fl-warn-f
Jun 19, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/3272-unify-fl-warn-f

Conversation

@zackees

@zackees zackees commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #3272.

One FL_WARN(...) macro now accepts BOTH stream-style and printf-style call sites — no more _F suffix needed in new code. Macro-level argument-count dispatch routes single-arg calls to the existing sstream/log_emit path and two-or-more-arg calls to the existing log_emit_f path.

```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-channel FL_LOG_* family, and the per-channel FL_LOG_*_ASYNC_MAIN family.

Backward compatibility

All _F macros are preserved as one-line aliases. Every existing call site of FL_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 _F suffix.

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

  • Disabled-platform behavior change (LOW): when FASTLED_LOG_VERBOSITY=0 or !SKETCH_HAS_LARGE_MEMORY, all macros now 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 and all per-channel _F variants, 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 under FASTLED_LOG_*_ENABLED (e.g. parlio_buffer_calc.h:238's uncappedCapacity) and broke the build.
  • New macros added (symmetric with existing API): FL_INFO_F, FL_INFO_F_IF are net-new aliases (master had no printf form for FL_INFO).

Implementation

A small _FL_VA_PICK17 macro + 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>_M helpers.

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 injects fl::sstream() as the LHS. Routing through a function call would force the << chain to evaluate standalone, which fails (const char* has no operator<<(float)).

Test plan

  • bash test --cpp — 331/331 passed
  • bash lint — clean
  • New tests in tests/fl/log/log.hpp verify both stream and printf forms of FL_WARN/FL_ERROR/FL_INFO/FL_PRINT/FL_WARN_IF, plus FL_WARN_F / FL_ERROR_F / FL_PRINT_F aliases.
  • Pre-existing test failures (DemoReel100, ArrayOfLedArrays, ClientValidation, Downscale, fl_stl_isr in parallel runs) reproduce on master — not introduced by this PR.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Logging macros now accept both stream-style and printf-style payloads with the same call syntax, without needing separate suffix variants.
    • Updated async and hardware-category logging to follow the same unified argument handling and forwarding behavior.
  • Tests

    • Added coverage to verify correct payload-style dispatch for warnings, errors, info, and print logging, including conditional cases and alias suffix behavior.

…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]>
@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 804220a4-e938-4430-a312-00b9b4833c5f

📥 Commits

Reviewing files that changed from the base of the PR and between d432b21 and 2aeb5f7.

📒 Files selected for processing (2)
  • src/fl/log/log.h
  • tests/fl/log/log.hpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/fl/log/log.hpp
  • src/fl/log/log.h

📝 Walkthrough

Walkthrough

src/fl/log/log.h adds _FL_VA_DISPATCH argument-count plumbing and rewrites FL_ERROR, FL_WARN, FL_INFO, FL_PRINT, all hardware category macros (FL_LOG_SPI etc.), and all async macros to accept both stream-style and printf-style arguments. _F-suffix macros become aliases of the unified entry points. tests/fl/log/log.hpp adds a test suite validating the new dispatch paths.

Changes

Unified Logging Macro Dispatch

Layer / File(s) Summary
Documentation updates and core dispatch mechanism
src/fl/log/log.h
Updates header comments describing backward-compatible FL_LOG_*_ENABLED aliases, verbosity gating, and centralized logging paths; introduces _FL_VA_DISPATCH argument-count macro and rewrites FL_ERROR and FASTLED_ERROR from single-argument stream-only to unified variadic macros that dispatch single-arg payloads through log_emit via fl::sstream and multi-arg payloads through log_emit_f; updates _F, _IF, and disabled no-op variants to match.
FL_WARN, FL_INFO, FL_PRINT unification
src/fl/log/log.h
Applies the same _FL_VA_DISPATCH pattern to FL_WARN/FASTLED_WARN, FL_INFO/FASTLED_INFO, and FL_PRINT; updates FL_WARN_ONCE, FL_WARN_EVERY, FL_WARN_IF, FL_INFO_IF, FL_INFO_ONCE, and FL_PRINT_EVERY to accept variadic payloads; makes _F variants aliases to the unified base macros; disabled no-op branches maintain matching variadic signatures.
Hardware category macro variadic forwarding
src/fl/log/log.h
Converts enabled forms of FL_LOG_SPI, FL_LOG_RMT, FL_LOG_PARLIO, FL_LOG_AUDIO, FL_LOG_INTERRUPT, FL_LOG_FLEXIO, and FL_LOG_OBJECTFLED to variadic forms that forward to FL_WARN(__VA_ARGS__); _F variants become direct aliases; disabled branches remain no-ops with matching signatures.
Async logging macro variadic unification
src/fl/log/log.h
Replaces FL_LOG_ASYNC(logger, X) with variadic FL_LOG_ASYNC(logger, ...) dispatching via internal per-form helpers; FL_LOG_ASYNC_F becomes an alias; per-category ASYNC_MAIN macros for all seven hardware categories become variadic and forward via FL_LOG_ASYNC(...); _F variants are aliased and ASYNC_FLUSH macros are updated to flush both ISR and main loggers.
Unified dispatch test suite
tests/fl/log/log.hpp
Adds coverage for arity-based dispatch of FL_WARN, FL_ERROR, FL_INFO, and FL_PRINT without _F suffix; validates percent-literal single-arg routes through stream path, _F alias compilation, stream chaining, and FL_WARN_IF printf dispatch under both true and false conditions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • FastLED/FastLED#2791: Also modifies the core FL_ERROR/FL_WARN/FL_INFO/FL_PRINT macro definitions in src/fl/log/log.h, specifically adding FASTLED_LOG_RUNTIME_ENABLED-driven no-op gating that this PR's updated disabled-branch no-op forms must coexist with.
  • FastLED/FastLED#2968: Routes FL_WARN/FL_ERROR/FL_INFO emission through fl::detail::log_emit, the same central helper that this PR's single-arg dispatch path targets.

Poem

🐇 Hop hop, one macro to rule them all,
No more _F suffix at every call!
Stream or printf, the rabbit picks right,
_FL_VA_DISPATCH shines bright.
The log family unified at last —
Verbose suffixes are a thing of the past! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: unifying FL_WARN and FL_WARN_F logging macros via argument-count dispatch, with reference to the linked issue #3272.
Linked Issues check ✅ Passed The PR fully implements the scope of issue #3272: unified variadic dispatch for FL_WARN/FL_ERROR/FL_INFO/FL_PRINT and per-channel macros, with _F variants as aliases, backward-compatible, and all tests passing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #3272: macro unification, dispatch mechanism, test coverage, and ASCII normalization. No migration of call sites or binary-size optimization work outside the stated scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/3272-unify-fl-warn-f

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/fl/log/log.hpp (1)

470-480: ⚡ Quick win

Add FL_INFO_F (and FL_INFO_F_IF) alias compile-path coverage.

This suite validates _F aliases 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 _F alias 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

📥 Commits

Reviewing files that changed from the base of the PR and between 74233c3 and d432b21.

📒 Files selected for processing (2)
  • src/fl/log/log.h
  • tests/fl/log/log.hpp

Comment thread tests/fl/log/log.hpp Resolved
- 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]>
@zackees
zackees merged commit dc9a0d4 into master Jun 19, 2026
13 checks passed
@zackees
zackees deleted the feat/3272-unify-fl-warn-f branch June 19, 2026 17:59
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

refactor(log): unify FL_WARN/FL_WARN_F via overload dispatch (drop the _F suffix family)

1 participant