Skip to content

Disable debug logging in release builds #420

Description

@kraenhansen

Tracking the TODO in packages/host/cpp/Logger.cpp.

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);
}

log_debug formats and emits unconditionally — there is no build-configuration guard anywhere in Logger.cpp. The host calls it on every addon load: per-library "Found napi_register_module_v1", per-library "Failed to find…", and the resolution chatter in CxxNodeApiHostModule.cpp. In a shipped app that is per-addon logging to logcat / os_log that no user asked for, plus the string formatting cost on a path that runs during startup.

Two things to decide:

  1. What "release" means here. NDEBUG is the obvious hook and is set by the CMake Release/MinSizeRel configurations, but RelWithDebInfo also defines it — which may or may not be what we want given Support RelWithDebInfo in CMake RN #255. React Native's own NDEBUG/__DEV__ split is worth mirroring rather than inventing something.
  2. Compile out vs. gate at runtime. Compiling the body away removes the formatting cost entirely; a runtime level check keeps the ability to turn logging on when diagnosing a release-only problem — which, given that release-mode issues are the hard ones, has real value. A compile-time default with a runtime override is the usual compromise.

log_warning and log_error should keep firing in release regardless.

Also a prerequisite for making release-mode CI runs readable — see the iOS Release-mode CI issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AutomatableAn issue we expect to be fixed using automation.C++Host 🏡Our `react-native-node-api-modules` package

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions