Skip to content

chore: demo app log listener cleanup#2650

Closed
nan-li wants to merge 1 commit into
mainfrom
chore/demo_app_logs
Closed

chore: demo app log listener cleanup#2650
nan-li wants to merge 1 commit into
mainfrom
chore/demo_app_logs

Conversation

@nan-li
Copy link
Copy Markdown
Contributor

@nan-li nan-li commented May 19, 2026

Description

One Line Summary

Clean up duplicate noisy logs, and consolidate all demo logs into one tag so they are easy to find.

Details

Motivation

  • Logs were being duplicated in logcat
  • remove extraneous logs
  • Make all demo app logs TAG = "OneSignalDemo" so we don't get confused with what things like "OneSignalService" "OneSignalExample" "OneSignalRepository" are about.

Scope

Only demo app

Testing

Unit testing

OPTIONAL - Explain unit tests added, if not clear in the code.

Manual testing

Run example app and see logs

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

* Logs were being duplicated in logcat
* remove extraneous logs
@nan-li nan-li requested a review from a team May 19, 2026 22:56
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

LGTM — demo-app-only log cleanup; the inline note about duplicate logcat lines in the throwable overloads is a minor pre-existing nit, not blocking.

Extended reasoning...

Overview

This PR is scoped entirely to examples/demo/app/ — the OneSignal SDK demo app. It consolidates demo logging onto a single LogManager.TAG = "OneSignalDemo" constant, drops per-class TAG constants (OneSignalExample, OneSignalService, OneSignalRepository, OneSignalHMS, MainViewModel, TooltipHelper), removes redundant android.util.Log calls in MainViewModel, simplifies LogManager (drops (tag, …) overloads, removes legacy info/debug/warn/error aliases, introduces a UI-only appendToPanel() used by the SDK log listener to avoid double-logging), and updates callers to the simplified API. No production SDK code under OneSignal/ or OneSignalSDK/ is touched.

Security risks

None. There are no auth, crypto, permission, or input-handling changes; this is purely log-tag bookkeeping. The pre-existing demo OneSignalService still uses subscription IDs (not REST API keys) per its existing comments, and that path is unchanged here.

Level of scrutiny

Low. Demo/example code with no shipped-SDK surface, no public API change, and mechanical call-site updates. A human reviewer would essentially be skimming for typos.

Other factors

The bug hunting system flagged one pre-existing issue: LogManager.e(msg, throwable) / w(msg, throwable) still emit two logcat lines because they call Log.e/w(…, throwable) and then route through log(…) which writes again. The PR introduced appendToPanel() precisely to break this duplication on the SDK-listener path, so this is the exact category the PR targets; however, it predates this PR and only affects four demo call sites in OneSignalService.kt. The inline comment is sufficient — not blocking for approval given the demo-only blast radius.

Comment on lines +75 to 83
fun e(message: String, throwable: Throwable) {
Log.e(TAG, message, throwable)
log("$message: ${throwable.message}", LogLevel.ERROR)
}

fun w(tag: String, message: String, throwable: Throwable) {
Log.w(tag, message, throwable)
log(tag, "$message: ${throwable.message}", LogLevel.WARN)
fun w(message: String, throwable: Throwable) {
Log.w(TAG, message, throwable)
log("$message: ${throwable.message}", LogLevel.WARN)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟣 The throwable overloads LogManager.e(message, throwable) and LogManager.w(message, throwable) at lines 75-83 still produce duplicate logcat lines: they call Log.e/Log.w(TAG, message, throwable) and then call log(...), which itself emits a second Log.e/Log.w(TAG, message). This is a pre-existing issue, but it's precisely the duplication category this PR targets — and appendToPanel() was introduced for exactly this case. Fix by replacing the log(...) call with appendToPanel(...) in both overloads. While here, the KDoc on log() at lines 26-28 is now stale on both counts: the tag parameter no longer exists, and the SDK log listener bypasses log() for appendToPanel().

Extended reasoning...

What the bug is

After this PR, LogManager.kt has two throwable overloads:

fun e(message: String, throwable: Throwable) {
    Log.e(TAG, message, throwable)                              // logcat write #1 (with stack trace)
    log("$message: ${throwable.message}", LogLevel.ERROR)       // routes through log() → logcat write #2
}

fun w(message: String, throwable: Throwable) {
    Log.w(TAG, message, throwable)
    log("$message: ${throwable.message}", LogLevel.WARN)
}

And log() itself does:

fun log(message: String, level: LogLevel) {
    when (level) {
        LogLevel.DEBUG -> Log.d(TAG, message)
        LogLevel.INFO  -> Log.i(TAG, message)
        LogLevel.WARN  -> Log.w(TAG, message)
        LogLevel.ERROR -> Log.e(TAG, message)
    }
    appendToPanel(message, level)
}

So every LogManager.e(msg, e) / LogManager.w(msg, w) call produces two logcat entries under the OneSignalDemo tag — one with the stack trace (good), and one with "$msg: ${throwable.message}" appended (the duplicate).

Step-by-step proof

Consider the call site OneSignalService.kt:101:

} catch (e: Exception) {
    LogManager.e("Error sending notification", e)
    ...
}

When e is, say, IOException("Connection refused"):

  1. LogManager.e("Error sending notification", e) is invoked → matches the throwable overload at line 75.
  2. Logcat line 1: Log.e("OneSignalDemo", "Error sending notification", e) — writes "Error sending notification" plus the full stack trace.
  3. Then log("Error sending notification: Connection refused", LogLevel.ERROR) is called at line 77.
  4. Inside log(), the LogLevel.ERROR branch fires: Logcat line 2: Log.e("OneSignalDemo", "Error sending notification: Connection refused").
  5. Then appendToPanel(...) adds the message to the UI panel (correct).

Result in logcat:

E/OneSignalDemo: Error sending notification
                 java.io.IOException: Connection refused
                     at ...
                     at ...
E/OneSignalDemo: Error sending notification: Connection refused

Both lines are about the same error. The first has the full trace; the second is a redundant summary. This is exactly the "duplicate noisy logs" pattern the PR's description calls out as motivation.

Why existing code doesn't prevent it

The PR introduced appendToPanel() as the UI-only primitive precisely to break this duplication on the SDK-listener path (see MainApplication.kt:53, which the PR changed from LogManager.log(...) to LogManager.appendToPanel(...)). But the throwable overloads were not updated to follow the same pattern — they still route through log() for the UI-side append, which carries the unwanted second logcat write along with it.

Impact

Demo app only (no production impact). Affected callers all live in OneSignalService.kt:

  • Line 101: LogManager.e("Error sending notification", e)
  • Line 160: LogManager.e("Error sending custom notification", e)
  • Line 209: LogManager.e("Error parsing user response", e)
  • Line 218: LogManager.e("Error fetching user", e)

Each one will emit two E/OneSignalDemo lines per exception. Noisy and exactly contradicts the PR's stated goal.

How to fix

Replace log(...) with appendToPanel(...) in both throwable overloads — logcat is already covered by the Log.e/Log.w call with the throwable above it:

fun e(message: String, throwable: Throwable) {
    Log.e(TAG, message, throwable)
    appendToPanel("$message: ${throwable.message}", LogLevel.ERROR)
}

fun w(message: String, throwable: Throwable) {
    Log.w(TAG, message, throwable)
    appendToPanel("$message: ${throwable.message}", LogLevel.WARN)
}

While editing this file, also refresh the stale KDoc on log() at lines 26-28 ("Log with custom tag (used by SDK log listener)") — the tag parameter was removed in this same PR (TAG is hardcoded), and MainApplication.kt:53 was changed to call appendToPanel(...) directly, so the SDK listener no longer goes through log().

Severity

pre_existing — the dual-call pattern existed before this PR. Flagged because (a) the PR's explicit motivation is "Logs were being duplicated in logcat," (b) the PR added appendToPanel() as the exact primitive to fix this, and (c) the PR modified these very function signatures (dropping the tag parameter) so the fix is one keyword away.

Copy link
Copy Markdown
Contributor

@fadi-george fadi-george left a comment

Choose a reason for hiding this comment

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

im working on cleaning the demo

@github-actions
Copy link
Copy Markdown
Contributor

📊 Diff Coverage Report

✓ Coverage check passed (no source files changed)

📥 View workflow run

@nan-li
Copy link
Copy Markdown
Contributor Author

nan-li commented May 19, 2026

im working on cleaning the demo

thanks, sounds good, the noisy logs were getting to me

@nan-li nan-li closed this May 19, 2026
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.

2 participants