Repository navigation
Description
Why this issue exists
Split from #3158. That issue conflates two separable goals:
- API ergonomics — unify the stream-style
FL_WARN(X)and printf-styleFL_WARN_F(fmt, ...)into a single entry point so callers don't have to pick a suffix per call site. - Binary-size payoff — eliminate per-site
fl::sstream operator<<template instantiations to recover ~5–10 KB on ESP32-S3 (see Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886).
(1) is a small, contained change (~20 lines in src/fl/log/log.h) with no call-site churn. (2) is ~400 call-site migrations spread across many PRs, and decisions about format-string safety, NANO-libc compatibility, and the clang-tool checker. Lumping them together is what got #3158 stuck.
This issue tracks only (1) so it can ship independently. #3158 remains the home for the size-reduction migration.
Current state (as of 2026-06-19)
src/fl/log/log.h exposes a doubled macro surface — every stream-style macro has a _F twin:
// log.h:275 FL_WARN(X) → fl::sstream() << X → log_emit
// log.h:279 FL_WARN_F(fmt, ...) → log_emit_f(fmt, ...)
// log.h:283 FL_WARN_IF / FL_WARN_F_IF
// log.h:288 FL_WARN_ONCE / FL_WARN_F_ONCE
// log.h:313 FL_WARN_EVERY / FL_WARN_F_EVERY
// log.h:240 FL_ERROR / FL_ERROR_F (+ _IF variants)
// log.h:525 FL_PRINT_F
// log.h:565+ FL_LOG_{SPI,RMT,PARLIO,AUDIO,INTERRUPT,FLEXIO,OBJECTFLED}_F (+ASYNC variants)Every `_F` macro adds a name to the public surface, doubles documentation/maintenance, and forces callers to choose between stream- and printf-style at the syntactic level even though both target the same backend prefix-format chain.
Proposed approach: overload-based dispatch
Replace the dual-macro design with one macro per log level whose backend is a function template that overload-resolves on argument count:
```cpp
namespace fl { namespace detail {
// Single-argument form → stream style (legacy operator<< chain compiles unchanged)
template
void log_dispatch(log_kind k, const char* f, int l, T&& body) FL_NOEXCEPT {
fl::sstream s;
s << fl::forward(body);
log_emit(k, f, l, s);
}
// Multi-argument form → printf style (existing log_emit_f path)
template <typename... Args>
void log_dispatch(log_kind k, const char* f, int l,
const char* fmt, Args&&... args) FL_NOEXCEPT {
log_emit_f(k, f, l, fmt, args...);
}
}} // namespace fl::detail
#define FL_WARN(...) ::fl::detail::log_dispatch(
::fl::detail::log_kind::WARN,
::fl::fastled_file_offset(FILE), int(LINE),
VA_ARGS)
```
Behavior by call-site shape:
| Call site | Args after macro routing | Resolved overload |
|---|---|---|
| `FL_WARN("plain literal")` | 1 | stream form (no `%` interpretation — safe) |
| `FL_WARN("foo " << x << " bar")` | 1 (chained expression) | stream form (existing behavior unchanged) |
| `FL_WARN("got %d items", n)` | 2+ | printf form (replaces `FL_WARN_F` use) |
| `FL_WARN("100% loaded")` | 1 | stream form — no format interpretation, no crash |
All current `FL_WARN(X)` call sites compile unchanged. All current `FL_WARN_F(fmt, ...)` call sites work after dropping the `_F` suffix.
Scope of work
- Add the
log_dispatchtemplate overload set infl/log/log.h(next to existinglog_emit/log_emit_f) - Rewrite the active `FL_WARN` macro (and `FL_ERROR`, `FL_INFO`, `FL_PRINT`) to route through `log_dispatch` via `VA_ARGS`
- Verify `FL_WARN_IF`, `FL_WARN_ONCE`, `FL_WARN_EVERY` still work without the `_F` twins (they just expand to `FL_WARN(...)`)
- Keep `FL_WARN_F` / `FL_ERROR_F` / etc. as deprecation aliases for one release cycle:
- `#define FL_WARN_F(...) FL_WARN(VA_ARGS)`
- Optionally annotated with a `#pragma GCC warning` or compile-time deprecation note
- Apply the same treatment to per-channel macros: `FL_LOG_SPI_F`, `FL_LOG_RMT_F`, `FL_LOG_PARLIO_F`, `FL_LOG_AUDIO_F`, `FL_LOG_INTERRUPT_F`, `FL_LOG_FLEXIO_F`, `FL_LOG_OBJECTFLED_F` and their `ASYNC_MAIN_F` variants
- Remove `FL_WARN_F`-only test cases (or convert them to `FL_WARN` to prove the unified path)
- Update the `legacy_log_macro_checker.py` lint rule to point users at `FL_WARN` only
Known limitation: format-string safety
`attribute((format(printf, N, M)))` does not apply to function templates. The compile-time format-string check that #3158 calls for cannot live on `log_dispatch`. Two acceptable paths:
- Keep the existing free function `fl::printf(const char* fmt, ...)` (in `fl/stl/stdio.h`) annotated with `format(printf,1,2)` so the underlying call is still attribute-checked.
- Move format-string lint to the dedicated clang-tool in `ci/lint_cpp_rs/` (already part of perf(log): migrate fl::sstream to printf-style backend for ~5-10 KB on ESP32-S3 (split from #3122 B2 / refs #2856 item 3.2) #3158's plan) — that's the correct long-term home regardless.
Neither blocks this issue; the safety improvements are #3158 / #3174 territory.
Non-goals (deferred to #3158)
- ~5–10 KB binary-size reduction on ESP32-S3 — requires actually migrating ~400 call sites from `<<` chains to format strings, which this issue does not do.
- Newlib NANO compatibility audit for `%f` / `%lld` in format strings.
- The `attribute((format(printf,...)))` lint infrastructure.
- The `fl::printf` placeholder extensions tracked in feat(format): add generic fl::printf placeholders and mismatch-safety tests #3174.
Acceptance
- `FL_WARN_F`, `FL_ERROR_F`, `FL_PRINT_F`, and the `FL_LOG_*_F` family compile only as aliases to their non-`_F` counterparts.
- All existing `FL_WARN(X)` (stream-style) call sites compile unchanged.
- All existing `FL_WARN_F(fmt, ...)` (printf-style) call sites compile unchanged through the alias.
- A new call `FL_WARN("got %d items", n)` without the `_F` suffix produces identical output to the old `FL_WARN_F("got %d items", n)`.
- No binary-size regression on the ESP32-S3 NEOPIXEL Blink baseline (this is an API change, not a size change — the size win is perf(log): migrate fl::sstream to printf-style backend for ~5-10 KB on ESP32-S3 (split from #3122 B2 / refs #2856 item 3.2) #3158).
- All host unit tests pass with sanitizers (`bash test --debug`).
Cross-references
- Parent / sibling: perf(log): migrate fl::sstream to printf-style backend for ~5-10 KB on ESP32-S3 (split from #3122 B2 / refs #2856 item 3.2) #3158 (the binary-size migration this issue is split from).
- Related: feat(format): add generic fl::printf placeholders and mismatch-safety tests #3174 (`fl::printf` placeholder + mismatch-safety work that builds on the unified entry point).
- Macro definitions live in `src/fl/log/log.h` lines 240–355 (entry-point macros) and 565–845 (per-channel `_F` macros).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
refactor(log): unify FL_WARN/FL_WARN_F via argument-count dispatch (#…