diff --git a/.changeset/release-debug-logging.md b/.changeset/release-debug-logging.md new file mode 100644 index 00000000..218065a6 --- /dev/null +++ b/.changeset/release-debug-logging.md @@ -0,0 +1,10 @@ +--- +"react-native-node-api": patch +--- + +Stop emitting `log_debug`'s per-addon diagnostic chatter (library +found/loaded, symbol resolution, ...) in release builds. It is now compiled +out in `NDEBUG` builds (CMake's `Release`/`MinSizeRel`/`RelWithDebInfo` +configurations, and Xcode's default `Release` configuration), mirroring React +Native's own dev/release logging split. `log_warning` and `log_error` are +unaffected and keep firing in every build type. diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md index 173babe3..31fda3c4 100644 --- a/.claude/CLAUDE.md +++ b/.claude/CLAUDE.md @@ -4,6 +4,33 @@ Guidance specific to Claude Code sessions that open pull requests against this repository (including automated/scheduled sessions). See the root `CLAUDE.md` and `AGENTS.md` for everything else. +## Keep inline comments very brief — put the color in the PR description + +Default to **no comment at all**. Write one only when it carries knowledge a +reader cannot get from the code itself plus a `git blame` pointing at the PR +that introduced it. When you do write one, keep it to a line or two. + +Rationale, rejected alternatives, benchmark numbers, "we tried X and it +didn't work", links to upstream issues, and anything that reads as a history +lesson belong in the **PR description** (and, where user-facing, the +changeset) — not in the source. Those places are where a reader who has +already found the line via `git blame` will end up anyway, and they don't +have to be maintained as the code around them changes. + +Concretely, do not write comments that: + +- restate what the next line already says; +- explain why an alternative implementation was _not_ chosen; +- narrate the change (`// now compiled out in release builds`) — that is a + commit message, and it goes stale the moment the code moves; +- document a well-known toolchain fact (e.g. what `NDEBUG` means) that a + reader can look up. + +Comments that _do_ earn their place: a non-obvious constraint the compiler or +platform imposes, a workaround with the exact condition that makes it +removable (see the upstream-fix guidance in `AGENTS.md`), or a subtle +invariant a future edit could silently break. + ## Attach CI labels when you open a PR `.github/workflows/check.yml`'s `pull_request` trigger only fires on diff --git a/packages/host/cpp/Logger.cpp b/packages/host/cpp/Logger.cpp index b863fcdf..ce9d7c0c 100644 --- a/packages/host/cpp/Logger.cpp +++ b/packages/host/cpp/Logger.cpp @@ -63,13 +63,15 @@ void log_message_internal(LogLevel level, const char *format, va_list args) { namespace callstack::react_native_node_api { +#ifndef NDEBUG void log_debug(const char *format, ...) { - // TODO: Disable logging in release builds va_list args; va_start(args, format); log_message_internal(LogLevel::Debug, format, args); va_end(args); } +#endif + void log_warning(const char *format, ...) { va_list args; va_start(args, format); diff --git a/packages/host/cpp/Logger.hpp b/packages/host/cpp/Logger.hpp index c064e7da..7bec0047 100644 --- a/packages/host/cpp/Logger.hpp +++ b/packages/host/cpp/Logger.hpp @@ -3,7 +3,16 @@ #include namespace callstack::react_native_node_api { + +// Inline (rather than a no-op in Logger.cpp) to let the optimizer drop the +// argument evaluation at every call site. +#ifdef NDEBUG +inline void log_debug(const char *, ...) {} +#else void log_debug(const char *format, ...); +#endif + void log_warning(const char *format, ...); void log_error(const char *format, ...); + } // namespace callstack::react_native_node_api