Skip to content

Feat: add public log listener methods#2311

Merged
jkasten2 merged 2 commits intomainfrom
feat/add-log-listener
Jun 4, 2025
Merged

Feat: add public log listener methods#2311
jkasten2 merged 2 commits intomainfrom
feat/add-log-listener

Conversation

@jkasten2
Copy link
Copy Markdown
Member

@jkasten2 jkasten2 commented Jun 3, 2025

Description

One Line Summary

Adds the following new public methods to allow an app developer to capture logs as strings at runtime.

Details

Adds the following new public methods:

  • OneSignal.Debug.addLogListener
  • OneSignal.Debug.removeLogListener

These new methods provide a way to capture all SDK log entires at runtime, allowing the app developer to store these and/or send them to their server.

The log listener is independent of logLevel, all message are always sent to listeners.

Motivation

App developers want a way to capture all SDK logs and send them to their server to debug issues in production.

Scope

Only add new methods to OneSignal.Debug to allow of capturing logs at runtime.

Testing

Unit testing

Added a new LoggingTests class to cover the new public methods.

Manual testing

Tested on an Android 15 emulator.

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
  • 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
    • Failing due to unrelated flaky OperationRepoTests test.
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

Adds the following new public methods:
* OneSignal.Debug.addLogListener
* OneSignal.Debug.removeLogListener

These new methods provide a way to capture all SDK log entires at
runtime, allowing the app developer to store these and/or send them to
their server.

The log listener is independent of logLevel, all message are always
sent to listeners.
@jkasten2 jkasten2 changed the title add public log listener methods Feat: add public log listener methods Jun 3, 2025
@jkasten2 jkasten2 requested review from jinliu9508 and nan-li June 3, 2025 23:49
@jkasten2 jkasten2 force-pushed the feat/add-log-listener branch from 5707ab8 to fda14d2 Compare June 4, 2025 16:57
Split log level and alert level logging into their own methods to make
the code easier to follow.
@jkasten2 jkasten2 force-pushed the feat/add-log-listener branch from fda14d2 to 24ed613 Compare June 4, 2025 18:00
Copy link
Copy Markdown
Contributor

@jinliu9508 jinliu9508 left a comment

Choose a reason for hiding this comment

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

I added Logging.log inside the onLogEvent and it looks like it is creating logs non-stop. Should we add a note to not calling log inside the log event?

@jkasten2
Copy link
Copy Markdown
Member Author

jkasten2 commented Jun 4, 2025

I added Logging.log inside the onLogEvent and it looks like it is creating logs non-stop. Should we add a note to not calling log inside the log event?

  • The OneSignal Logging class shouldn't be used outside of the OneSignal SDK, it's been public since the 5.0.0 release but it was not indented and isn't documented.
  • The logging listener isn't intended to be used inside the SDK, only externally by apps.

Given the above I don't think we need account for this.

@jkasten2 jkasten2 merged commit f7f82ed into main Jun 4, 2025
1 of 5 checks passed
@jkasten2 jkasten2 deleted the feat/add-log-listener branch June 4, 2025 20:42
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