Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/release-debug-logging.md
Original file line number Diff line number Diff line change
@@ -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.
27 changes: 27 additions & 0 deletions .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/host/cpp/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions packages/host/cpp/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
#include <string>

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
Loading