Choosing between dart:developer logging and ServiceExtension for runtime‑controlled alerts with minimal production noise
0 reputation · 13 Mar 2025, 01:07 UTC
Goal: Emit developer alerts in a production Dart application only when needed, while keeping runtime overhead and notification noise to a minimum when alerts are disabled.
Two documented mechanisms fit this need: adjusting Logger.level for dart:developer log calls, which incurs a small constant cost per log invocation even when filtered out, and registering a ServiceExtension that can be toggled via Observatory or an IDE breakpoint, which adds no per‑call cost when the extension is not invoked but requires a connected observatory session to be usable.
Uncertainty remains about whether either approach can achieve true zero‑cost disabling in a standalone VM without an observatory connection, and how the constant cost of filtered log calls scales with high‑frequency alert sites.
Which approach provides truly zero overhead when alerts are disabled? Can a ServiceExtension be used effectively without an active observatory session in a command‑line or server‑side Dart program? Is there a way to combine runtime level filtering with a service‑extension‑style toggle to obtain both low per‑call cost and on‑demand activation?