Skip to content

Logging: introduce log levels on JS and Android - #70

Merged
ofalvai merged 1 commit into
masterfrom
push-rtrwzqsknzvr
Sep 30, 2026
Merged

ofalvai merged 1 commit into
masterfrom
push-rtrwzqsknzvr

Conversation

@ofalvai

@ofalvai ofalvai commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Part of a series of logging-related PRs, see PR stack. OTA updates are hard to test (by users of this library, not us), so the CodePush logs are often the only proof of what an update did on a device.

Today, every JS line is a console.log and every Android line is a Log.d, so a failure looks the same as a normal step. Errors lose their stack. Some Android failures print only [CodePush] Exception, or go to printStackTrace() without setting the right log tag.

This PR adds log levels and fixe formatting. It keeps the message text almost the same. The PRs above in the stack change what gets logged.

Changes

  • JS: add info(), warn() and error() functions to our logging util. The bare log() is gone, so every call site needs to explicitly choose a logging level.
  • Android: A new CodePushLog.kt replaces CodePushUtils.log() and uses Android's Log.i, Log.w and Log.e.
  • About 30 call sites that logged only an exception now say which operation failed.
  • iOS: CPLog no longer prepends a newline, so there is no blank line before every message. The signature verification line uses CPLog now, so it has the [CodePush] prefix and shows up in the E2E log.

Decisions

  • iOS keeps CPLog without levels. The logging util uses NSLog, which doesn't support log levels. The modern replacement is the Swift-only os.Logger, so once we enable non-test Swift usage in this codebase, we can easily implement the same log levels as on Android. I added a TODO comment to the relevant code so that it's going to be a reminder for whoever touches that part of the codebase again.
  • JS-side CodePush.log is removed. It was exported but not in the typings. In theory, this is a breaking change, but because it was never exposed in the typings, I think this is acceptable. Also, I don't expect any app to use this exported CodePush.log() symbol for anything useful, it's absolutely an internal utility.
  • The Expo ClassCastException is an info line. It's expected on Expo, so a warning would only be noise.

Copilot AI balanced review requested due to automatic review settings September 29, 2026 19:33
@ofalvai
ofalvai added this pull request to stack #74 September 29, 2026 19:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Recurring LogBox warnings and missing exception stacks still affect update diagnostics.

Review effort: Balanced
Findings: 3 Medium severity

Open (3)
What changed in this PR

This PR gives CodePush’s JavaScript and Android logs severity levels while keeping native and JavaScript output recognizable across the update flow.

Changes:

  • Add info, warning, and error logging for JavaScript and Android call sites.
  • Improve failure messages and stack traces, and remove a leftover debug log.
  • Standardize iOS log formatting and update related test comments.
File Description
test/​test.mts Updates an iOS log-parsing comment.
logging.js Adds JavaScript log levels and error stacks.
ios/​CodePush/​CodePushUtils.m Removes the leading log newline.
ios/​CodePush/​CodePushUpdateUtils.m Uses the prefixed iOS logger.
CodePush.js Applies log levels to update and reporting paths.
android/​app/​src/​test/​java/​com/​microsoft/​codepush/​react/​CodePushUpdateManagerTest.kt Updates a logger test comment.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​SettingsManager.java Logs metadata warnings.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​FileUtils.java Logs file-operation warnings.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePushUtils.java Removes the old Android logger.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePushUpdateUtils.java Logs verification status and failures.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePushUpdateManager.java Logs update application and signature warnings.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePushTelemetryManager.java Logs report-parsing failures.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePushNativeModule.java Logs bridge and reload events; removes a debug line.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePushLog.kt Introduces the Android logger.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePushDialog.java Logs dialog-handler failures.
android/​app/​src/​main/​java/​com/​microsoft/​codepush/​react/​CodePush.java Logs bundle selection and rollback events.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread CodePush.js Outdated
await withTimeout(reportStatusDownload({ ...remotePackage, downloadDurationMs, status }), REPORT_STATUS_DOWNLOAD_TIMEOUT_MS);
} catch (err) {
log(`Report download status failed: ${err}`);
log.warn(`Failed to report download status. ${err}`);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, added a second err param to log.warn()

Comment thread CodePush.js
if (!remotePackage || updateShouldBeIgnored) {
if (updateShouldBeIgnored) {
log("An update is available, but it is being ignored due to having been previously rolled back.");
log.warn("An update is available, but it is being ignored due to having been previously rolled back.");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disagree, it's useful to keep logging the reason an available update is not installed for each launch. Makes debugging easier.

Comment thread android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java Outdated
- logging.js exports info/warn/error instead of a single log(). warn and
  error map to console.warn/console.error. error() includes the stack.
- Android: new CodePushLog.kt (Log.i/Log.w/Log.e) replaces
  CodePushUtils.log(). Exception-only call sites now have a context
  message instead of "[CodePush] Exception". printStackTrace() calls
  now go through the logger.
- iOS: CPLog no longer prepends a newline. The signature verification
  line uses CPLog, so it has the [CodePush] prefix.
- Remove the leftover [MyDebug] line and the untyped CodePush.log export.
- "Report status failed" and sync failures now log the error and stack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ofalvai
ofalvai marked this pull request as ready for review September 30, 2026 08:20
Comment thread CodePush.js
retryOnAppResume && retryOnAppResume.remove();
} catch (e) {
log(`Report status failed: ${JSON.stringify(statusReport)}`);
log.error(`Report status failed: ${JSON.stringify(statusReport)}`, e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Routine offline failures now surface as red LogBox errors on every sync and every app resume. Same in line 596.

checkForUpdate → sdk.queryUpdateWithCurrentPackage rejects whenever the device is offline or the CodePush server is unreachable.

Fix: use log.warn for the retried/recoverable network paths (sync's catch-all, tryReportStatus), matching the download-report call; keep error for the non-recoverable ones (callback threw, module not installed).

@ofalvai
ofalvai merged commit 8c20e80 into master Sep 30, 2026
6 checks passed
@ofalvai
ofalvai deleted the push-rtrwzqsknzvr branch September 30, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants