From c5b10c2d748c667dd5d5d99f072f62477fe12de1 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:58:07 +0530 Subject: [PATCH 01/20] minor fix in logging --- Apps/APN/src/services/CustomerIOService.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Apps/APN/src/services/CustomerIOService.js b/Apps/APN/src/services/CustomerIOService.js index 529d7834..888dfc0b 100644 --- a/Apps/APN/src/services/CustomerIOService.js +++ b/Apps/APN/src/services/CustomerIOService.js @@ -10,8 +10,9 @@ export const initializeCustomerIoSDK = (sdkConfig) => { } }; if (sdkConfig.debugMode) { - config.logLevel = CioLogLevel.debug; + config.logLevel = CioLogLevel.Debug; } + CustomerIO.initialize(config) }; From a8c6b9d643ecfdd937f448a299f9dc980e635714 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:58:18 +0530 Subject: [PATCH 02/20] native logger --- ios/wrappers/CioRctWrapper.swift | 4 + ios/wrappers/logging/CioLoggingEmitter.mm | 4 + ios/wrappers/logging/CioLoggingEmitter.swift | 91 ++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 ios/wrappers/logging/CioLoggingEmitter.mm create mode 100644 ios/wrappers/logging/CioLoggingEmitter.swift diff --git a/ios/wrappers/CioRctWrapper.swift b/ios/wrappers/CioRctWrapper.swift index e3e9c949..895767b8 100644 --- a/ios/wrappers/CioRctWrapper.swift +++ b/ios/wrappers/CioRctWrapper.swift @@ -8,10 +8,14 @@ import React class CioRctWrapper: NSObject { @objc var moduleRegistry: RCTModuleRegistry! + private var logger: CioLogger! @objc func initialize(_ configJson: AnyObject, logLevel: String) { do { + logger = CioLoggerWrapper.getInstance(moduleRegistry: moduleRegistry, logLevel: CioLogLevel(rawValue: logLevel) ?? .none) + + logger.debug("Initializing CIO with config: \(configJson)") let rtcConfig = try RCTCioConfig.from(configJson) let cioInitConfig = cioInitializeConfig(from: rtcConfig, logLevel: logLevel) CustomerIO.initialize(withConfig: cioInitConfig.cdp) diff --git a/ios/wrappers/logging/CioLoggingEmitter.mm b/ios/wrappers/logging/CioLoggingEmitter.mm new file mode 100644 index 00000000..779e1a32 --- /dev/null +++ b/ios/wrappers/logging/CioLoggingEmitter.mm @@ -0,0 +1,4 @@ +#import + +@interface RCT_EXTERN_REMAP_MODULE(CioLoggingEmitter, CioLoggingEmitter, RCTEventEmitter) +@end diff --git a/ios/wrappers/logging/CioLoggingEmitter.swift b/ios/wrappers/logging/CioLoggingEmitter.swift new file mode 100644 index 00000000..a5b2527d --- /dev/null +++ b/ios/wrappers/logging/CioLoggingEmitter.swift @@ -0,0 +1,91 @@ + +import React +import CioInternalCommon + +typealias CioLogger = CioInternalCommon.Logger + +@objc(CioLoggingEmitter) +class CioLoggingEmitter: RCTEventEmitter { + + fileprivate static var eventName = "CioLogEvent" + + fileprivate var hasObservers = false + + override func startObserving() { + hasObservers = true + } + + override func stopObserving() { + hasObservers = false + } + + override func supportedEvents() -> [String] { + [Self.eventName] + } + + override var methodQueue: dispatch_queue_t! { + DispatchQueue(label: Self.moduleName()) + } +} + + +class CioLoggerWrapper: CioLogger { + private(set) var logLevel: CioLogLevel + private var moduleRegistry: RCTModuleRegistry + + static func getInstance (moduleRegistry: RCTModuleRegistry, logLevel: CioLogLevel) -> CioLogger { + if let wrapper = DIGraphShared.shared.logger as? Self { + wrapper.logLevel = logLevel + wrapper.moduleRegistry = moduleRegistry + return wrapper + } + + let wrapper = CioLoggerWrapper(moduleRegistry: moduleRegistry, logLevel: logLevel) + DIGraphShared.shared.override(value: wrapper, forType: CioLogger.self) + return wrapper + } + + private init(moduleRegistry: RCTModuleRegistry, logLevel: CioLogLevel?) { + self.logLevel = logLevel ?? .none + self.moduleRegistry = moduleRegistry + } + + func setLogLevel(_ level: CioLogLevel) { + logLevel = level + } + + func debug(_ message: String) { + emit(message, level: .debug) + } + + func info(_ message: String) { + emit(message, level: .info) + } + + func error(_ message: String) { + emit(message, level: .error) + } + + private func emit(_ message: String, level: CioLogLevel) { + if shouldEmit(level: level), let emitter, emitter.hasObservers { + emitter.sendEvent(withName: CioLoggingEmitter.eventName, body: ["logLevel": level.rawValue, "message": message]) + } + } + + private func shouldEmit(level: CioLogLevel) -> Bool { + switch self.logLevel { + case .none: return false + case .error: + return level == .error + case .info: + return level == .error || level == .info + case .debug: + return true + } + } + + private var emitter: CioLoggingEmitter? { + moduleRegistry.module(forName: "CioLoggingEmitter") as? CioLoggingEmitter + } + +} From e8f75f2c0f1c33ca42343bc6c5759373ce4dc7a1 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:58:29 +0530 Subject: [PATCH 03/20] ts logger --- src/customerio-cdp.ts | 9 +++---- src/native-logger-listener.ts | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/native-logger-listener.ts diff --git a/src/customerio-cdp.ts b/src/customerio-cdp.ts index 10c2d894..059b3bc5 100644 --- a/src/customerio-cdp.ts +++ b/src/customerio-cdp.ts @@ -5,7 +5,7 @@ import {type IdentifyParams } from './cio-params'; // when they are implemented. // import { CustomerIOInAppMessaging } from './customerio-inapp'; // import { CustomerIOPushMessaging } from './customerio-push'; -// import { NativeLoggerListener } from './native-logger-listener'; +import { NativeLoggerListener } from './native-logger-listener'; const LINKING_ERROR = `The package 'customerio-reactnative' doesn't seem to be linked. Make sure: ` + @@ -28,10 +28,9 @@ export class CustomerIO { private static initialized = false; static readonly initialize = async (config: CioConfig) => { - // TODO: Initialize logger when it is implemented. - // if (config.logLevel && config.logLevel !== CioLogLevel.None) { - // NativeLoggerListener.initialize(); - // } + if (config.logLevel && config.logLevel !== CioLogLevel.None) { + NativeLoggerListener.initialize(); + } let logLevel = config.logLevel?.valueOf() ?? CioLogLevel.Error.valueOf(); NativeCustomerIO.initialize(config, logLevel); CustomerIO.initialized = true; diff --git a/src/native-logger-listener.ts b/src/native-logger-listener.ts new file mode 100644 index 00000000..29b38371 --- /dev/null +++ b/src/native-logger-listener.ts @@ -0,0 +1,49 @@ +import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; +import { CioLogLevel } from './cio-config'; + +const LINKING_ERROR = + `The package 'customerio-reactnative' doesn't seem to be linked. Make sure: ` + + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + + '- You rebuilt the app after installing the package\n' + + '- You are not using Expo Go\n'; + +const CioLoggingEmitter = NativeModules.CioLoggingEmitter + ? NativeModules.CioLoggingEmitter + : new Proxy( + {}, + { + get() { + throw new Error(LINKING_ERROR); + }, + } + ); + +export class NativeLoggerListener { + static initialize() { + const bridge = new NativeEventEmitter(CioLoggingEmitter); + bridge.addListener( + 'CioLogEvent', + (event: { logLevel: CioLogLevel; message: string }) => { + // if we just use console.log, it will log to the JS side but it will prevent RN default behavior of redirecting logs to the native side + // doing it async allows to be logged to the JS side and then to the native side + async function log() { + switch (event.logLevel) { + case CioLogLevel.Debug: + console.debug(event.message); + break; + case CioLogLevel.Info: + console.info(event.message); + break; + case CioLogLevel.Error: + console.error(event.message); + break; + default: + console.log(event); + break; + } + } + log(); + } + ); + } +} From d784bf86e9856de8be1983652ca9f1d4770718b4 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:06:41 +0530 Subject: [PATCH 04/20] CIO for differentiation --- src/native-logger-listener.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/native-logger-listener.ts b/src/native-logger-listener.ts index 29b38371..8dff5591 100644 --- a/src/native-logger-listener.ts +++ b/src/native-logger-listener.ts @@ -24,21 +24,23 @@ export class NativeLoggerListener { bridge.addListener( 'CioLogEvent', (event: { logLevel: CioLogLevel; message: string }) => { - // if we just use console.log, it will log to the JS side but it will prevent RN default behavior of redirecting logs to the native side - // doing it async allows to be logged to the JS side and then to the native side + // Using console.log will log to the JavaScript side but prevent + // React Native’s default behavior of redirecting logs to the native side. + // By doing it asynchronously, we ensure the logs are captured on both + // the JavaScript and native ends. async function log() { switch (event.logLevel) { case CioLogLevel.Debug: - console.debug(event.message); + console.debug("[CIO] " + event.message); break; case CioLogLevel.Info: - console.info(event.message); + console.info("[CIO] " + event.message); break; case CioLogLevel.Error: - console.error(event.message); + console.error("[CIO] " + event.message); break; default: - console.log(event); + console.log("[CIO] " + event); break; } } From 0d9bbea2a16d9030555561e7e8dbbeec40163434 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:57:36 +0530 Subject: [PATCH 05/20] added logs removed todos --- ios/wrappers/CioRctWrapper.swift | 6 +++--- src/customerio-cdp.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/wrappers/CioRctWrapper.swift b/ios/wrappers/CioRctWrapper.swift index 895767b8..ad202298 100644 --- a/ios/wrappers/CioRctWrapper.swift +++ b/ios/wrappers/CioRctWrapper.swift @@ -15,7 +15,7 @@ class CioRctWrapper: NSObject { do { logger = CioLoggerWrapper.getInstance(moduleRegistry: moduleRegistry, logLevel: CioLogLevel(rawValue: logLevel) ?? .none) - logger.debug("Initializing CIO with config: \(configJson)") + logger.debug("Initializing Customer.io SDK with config: \(configJson)") let rtcConfig = try RCTCioConfig.from(configJson) let cioInitConfig = cioInitializeConfig(from: rtcConfig, logLevel: logLevel) CustomerIO.initialize(withConfig: cioInitConfig.cdp) @@ -27,7 +27,7 @@ class CioRctWrapper: NSObject { } } } catch { - // TODO: Add log when logger feature is implemented + logger.error("Initializing Customer.io SDK failed with error \(error)") } } @@ -40,7 +40,7 @@ class CioRctWrapper: NSObject { } else if codableTraits != nil { CustomerIO.shared.identify(traits: codableTraits!) } else { - // TODO: Add log when logger feature is implemented + logger.error("Provide id or traits to identify a user profile.") } } diff --git a/src/customerio-cdp.ts b/src/customerio-cdp.ts index 059b3bc5..5586e896 100644 --- a/src/customerio-cdp.ts +++ b/src/customerio-cdp.ts @@ -1,7 +1,7 @@ import { NativeModules, Platform } from 'react-native'; import { CioLogLevel, type CioConfig } from './cio-config'; import {type IdentifyParams } from './cio-params'; -// TODO: Import the CustomerIOInAppMessaging, NativeLoggerListener and CustomerIOPushMessaging classes from their respective files +// TODO: Import the CustomerIOInAppMessaging and CustomerIOPushMessaging classes from their respective files // when they are implemented. // import { CustomerIOInAppMessaging } from './customerio-inapp'; // import { CustomerIOPushMessaging } from './customerio-push'; From be3665994ae755572b2db01b9507ed6f3ddab08b Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Wed, 4 Sep 2024 19:01:52 +0530 Subject: [PATCH 06/20] requiresMainQueueSetup --- ios/wrappers/logging/CioLoggingEmitter.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ios/wrappers/logging/CioLoggingEmitter.swift b/ios/wrappers/logging/CioLoggingEmitter.swift index a5b2527d..c9fd340f 100644 --- a/ios/wrappers/logging/CioLoggingEmitter.swift +++ b/ios/wrappers/logging/CioLoggingEmitter.swift @@ -8,9 +8,14 @@ typealias CioLogger = CioInternalCommon.Logger class CioLoggingEmitter: RCTEventEmitter { fileprivate static var eventName = "CioLogEvent" - + fileprivate var hasObservers = false - + + // Requires adding requiresMainQueueSetup method + // since it overrides init + @objc static override func requiresMainQueueSetup() -> Bool { + return true // Return true if the module must be initialized on the main queue + } override func startObserving() { hasObservers = true } @@ -18,7 +23,7 @@ class CioLoggingEmitter: RCTEventEmitter { override func stopObserving() { hasObservers = false } - + override func supportedEvents() -> [String] { [Self.eventName] } From 1e8b55b230b613a7c580e8af10cf8eb5aa955c71 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:10:44 +0530 Subject: [PATCH 07/20] android observers for logging --- .../logging/CustomerIOReactNativeLogger.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt new file mode 100644 index 00000000..79181700 --- /dev/null +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -0,0 +1,50 @@ +package io.customer.reactnative.sdk.logging +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.ReactMethod +import com.facebook.react.modules.core.DeviceEventManagerModule + +class CioLoggingEmitter(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { + + companion object { + const val EVENT_NAME = "CioLogEvent" + } + + private var hasObservers = false + + override fun getName(): String { + return "CioLoggingEmitter" + } + + override fun initialize() { + hasObservers = true + } + + override fun onCatalystInstanceDestroy() { + hasObservers = false + } + + @ReactMethod + fun startObserving() { + hasObservers = true + } + + @ReactMethod + fun stopObserving() { + hasObservers = false + } + + override fun getConstants(): MutableMap { + return hashMapOf("supportedEvents" to listOf(EVENT_NAME)) + } + + fun sendEvent(logLevel: String, message: String) { + if (hasObservers) { + reactApplicationContext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) + .emit(EVENT_NAME, mapOf("logLevel" to logLevel, "message" to message)) + } + } +} + + From 74240befaddb99c78bcc4673913ca2ce5d15d74f Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:22:52 +0530 Subject: [PATCH 08/20] CustomerIOReactNativeLoggingWrapper class --- .../logging/CustomerIOReactNativeLogger.kt | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index 79181700..3d4c075c 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -3,8 +3,11 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.modules.core.DeviceEventManagerModule +import io.customer.sdk.core.di.SDKComponent +import io.customer.sdk.core.util.CioLogLevel +import io.customer.sdk.core.util.Logger -class CioLoggingEmitter(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { +class CustomerIOReactNativeLoggingEmitter(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { companion object { const val EVENT_NAME = "CioLogEvent" @@ -47,4 +50,48 @@ class CioLoggingEmitter(reactContext: ReactApplicationContext) : ReactContextBas } } +class CustomerIOReactNativeLoggingWrapper private constructor( + private var moduleRegistry: ReactApplicationContext, + override var logLevel: CioLogLevel): Logger { + companion object { + fun getInstance(moduleRegistry: ReactApplicationContext, logLevel: CioLogLevel): CustomerIOReactNativeLoggingWrapper { + val instance = CustomerIOReactNativeLoggingWrapper(moduleRegistry, logLevel) +// DIGraphShared.shared.override(instance, CioLogger::class.java) + return instance + } + } + +// fun setLogLevel(level: CioLogLevel) { +// logLevel = level +// } + + override fun debug(message: String) { + emit(message, CioLogLevel.DEBUG) + } + + override fun info(message: String) { + emit(message, CioLogLevel.INFO) + } + + override fun error(message: String) { + emit(message, CioLogLevel.ERROR) + } + + private fun emit(message: String, level: CioLogLevel) { + if (shouldEmit(level)) { + val emitter = moduleRegistry.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) + emitter?.sendEvent(level.name, message) + } + } + + private fun shouldEmit(level: CioLogLevel): Boolean { + return when (logLevel) { + CioLogLevel.NONE -> false + CioLogLevel.ERROR -> level == CioLogLevel.ERROR + CioLogLevel.INFO -> level == CioLogLevel.ERROR || level == CioLogLevel.INFO + CioLogLevel.DEBUG -> true + } + } + +} \ No newline at end of file From ac244b7df78307d0d076b3fc194496aae20f8464 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:22:43 +0530 Subject: [PATCH 09/20] added logger module to package --- .../io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt index cf00e752..7aa1bf42 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt @@ -10,9 +10,11 @@ class CustomerIOReactNativePackage : ReactPackage { override fun createNativeModules(reactContext: ReactApplicationContext): List { val pushMessagingModule = RNCIOPushMessaging(reactContext) val inAppMessagingModule = RNCIOInAppMessaging(reactContext) + val loggerModule = CustomerIOReactNativeLoggingEmitter(reactContext) return listOf( inAppMessagingModule, pushMessagingModule, + loggerModule, NativeCustomerIOModule( reactContext = reactContext, pushMessagingModule = pushMessagingModule, From 0733635aaba51c95b9a0a632929990d1fd0faa8c Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:25:34 +0530 Subject: [PATCH 10/20] added missing import statement --- .../io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt index 7aa1bf42..d423e850 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt @@ -4,6 +4,7 @@ import com.facebook.react.ReactPackage import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.uimanager.ViewManager +import io.customer.reactnative.sdk.logging.CustomerIOReactNativeLoggingEmitter import io.customer.reactnative.sdk.messagingpush.RNCIOPushMessaging class CustomerIOReactNativePackage : ReactPackage { From 2d2f3302683c51fd1633a4876ca78b492dfe2c2d Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Thu, 5 Sep 2024 20:41:53 +0530 Subject: [PATCH 11/20] fixed listener issue --- .../sdk/logging/CustomerIOReactNativeLogger.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index 3d4c075c..e4775256 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -12,7 +12,7 @@ class CustomerIOReactNativeLoggingEmitter(reactContext: ReactApplicationContext) companion object { const val EVENT_NAME = "CioLogEvent" } - + private var listenerCount = 0 private var hasObservers = false override fun getName(): String { @@ -28,13 +28,13 @@ class CustomerIOReactNativeLoggingEmitter(reactContext: ReactApplicationContext) } @ReactMethod - fun startObserving() { - hasObservers = true + fun addListener(eventName: String) { + listenerCount++ } @ReactMethod - fun stopObserving() { - hasObservers = false + fun removeListeners(count: Int) { + listenerCount -= count } override fun getConstants(): MutableMap { From f767bb5074a2d4c40ea781a5202c95fe9ef47c5a Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Thu, 5 Sep 2024 20:58:19 +0530 Subject: [PATCH 12/20] cleanup --- .../logging/CustomerIOReactNativeLogger.kt | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index e4775256..0e84bf77 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -3,30 +3,21 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.modules.core.DeviceEventManagerModule -import io.customer.sdk.core.di.SDKComponent import io.customer.sdk.core.util.CioLogLevel import io.customer.sdk.core.util.Logger -class CustomerIOReactNativeLoggingEmitter(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { - +class CustomerIOReactNativeLoggingEmitter( + private val reactContext: ReactApplicationContext, +) : ReactContextBaseJavaModule(reactContext) { companion object { const val EVENT_NAME = "CioLogEvent" } private var listenerCount = 0 - private var hasObservers = false override fun getName(): String { return "CioLoggingEmitter" } - override fun initialize() { - hasObservers = true - } - - override fun onCatalystInstanceDestroy() { - hasObservers = false - } - @ReactMethod fun addListener(eventName: String) { listenerCount++ @@ -37,16 +28,10 @@ class CustomerIOReactNativeLoggingEmitter(reactContext: ReactApplicationContext) listenerCount -= count } - override fun getConstants(): MutableMap { - return hashMapOf("supportedEvents" to listOf(EVENT_NAME)) - } - - fun sendEvent(logLevel: String, message: String) { - if (hasObservers) { - reactApplicationContext - .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) - .emit(EVENT_NAME, mapOf("logLevel" to logLevel, "message" to message)) - } + fun sendEvent(eventName: String, params: String) { + reactContext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) + .emit(eventName, params) } } From 13ff3307d2de1627b4d121ecbeb32887f5c33b3a Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Sat, 7 Sep 2024 15:34:58 +0530 Subject: [PATCH 13/20] fixing logging --- .../reactnative/sdk/CustomerIOReactNativeModule.kt | 6 ++++-- .../sdk/logging/CustomerIOReactNativeLogger.kt | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt index 2e842877..f0fd6538 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt @@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableMap import io.customer.reactnative.sdk.constant.Keys import io.customer.reactnative.sdk.extension.toMap +import io.customer.reactnative.sdk.logging.CustomerIOReactNativeLoggingWrapper import io.customer.reactnative.sdk.messagingpush.RNCIOPushMessaging import io.customer.sdk.CustomerIO import io.customer.sdk.CustomerIOBuilder @@ -18,12 +19,13 @@ import io.customer.sdk.data.model.Region class NativeCustomerIOModule( - reactContext: ReactApplicationContext, + private val reactContext: ReactApplicationContext, private val pushMessagingModule: RNCIOPushMessaging, private val inAppMessagingModule: RNCIOInAppMessaging, ) : ReactContextBaseJavaModule(reactContext) { private val logger: Logger - get() = SDKComponent.logger + get() = CustomerIOReactNativeLoggingWrapper.getInstance(reactContext, CioLogLevel.DEBUG) + //SDKComponent.logger // If the SDK is not initialized, `CustomerIO.instance()` throws an exception private val customerIOInstance: CustomerIO? diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index 0e84bf77..3ec310ec 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -2,20 +2,24 @@ package io.customer.reactnative.sdk.logging import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod +import com.facebook.react.module.annotations.ReactModule import com.facebook.react.modules.core.DeviceEventManagerModule import io.customer.sdk.core.util.CioLogLevel import io.customer.sdk.core.util.Logger +@ReactModule(name = CustomerIOReactNativeLoggingEmitter.NAME) class CustomerIOReactNativeLoggingEmitter( private val reactContext: ReactApplicationContext, ) : ReactContextBaseJavaModule(reactContext) { companion object { const val EVENT_NAME = "CioLogEvent" + const val NAME = "CioLoggingEmitter" + } private var listenerCount = 0 override fun getName(): String { - return "CioLoggingEmitter" + return NAME } @ReactMethod @@ -35,6 +39,8 @@ class CustomerIOReactNativeLoggingEmitter( } } +private const val s = "Hello, Emit" + class CustomerIOReactNativeLoggingWrapper private constructor( private var moduleRegistry: ReactApplicationContext, override var logLevel: CioLogLevel): Logger { @@ -52,18 +58,22 @@ class CustomerIOReactNativeLoggingWrapper private constructor( // } override fun debug(message: String) { + println("Hello, debug!") emit(message, CioLogLevel.DEBUG) } override fun info(message: String) { + println("Hello, debug!") emit(message, CioLogLevel.INFO) } override fun error(message: String) { + println("Hello, debug!") emit(message, CioLogLevel.ERROR) } private fun emit(message: String, level: CioLogLevel) { + println("Hello, Emit!") if (shouldEmit(level)) { val emitter = moduleRegistry.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) emitter?.sendEvent(level.name, message) @@ -71,6 +81,7 @@ class CustomerIOReactNativeLoggingWrapper private constructor( } private fun shouldEmit(level: CioLogLevel): Boolean { + println("Hello, shouldEmit!") return when (logLevel) { CioLogLevel.NONE -> false CioLogLevel.ERROR -> level == CioLogLevel.ERROR From c6bbe05dd211961814cc5c193bdfa17f4fc60dae Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Sat, 7 Sep 2024 16:16:14 +0530 Subject: [PATCH 14/20] another try to get events in JS --- .../logging/CustomerIOReactNativeLogger.kt | 36 +++++++++++++++++-- src/native-logger-listener.ts | 1 + 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index 3ec310ec..ae96e0ec 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -1,4 +1,5 @@ package io.customer.reactnative.sdk.logging +import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod @@ -6,6 +7,7 @@ import com.facebook.react.module.annotations.ReactModule import com.facebook.react.modules.core.DeviceEventManagerModule import io.customer.sdk.core.util.CioLogLevel import io.customer.sdk.core.util.Logger +import kotlin.collections.buildMap @ReactModule(name = CustomerIOReactNativeLoggingEmitter.NAME) class CustomerIOReactNativeLoggingEmitter( @@ -33,12 +35,31 @@ class CustomerIOReactNativeLoggingEmitter( } fun sendEvent(eventName: String, params: String) { + println("I got control here") reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) - .emit(eventName, params) + .emit(EVENT_NAME, params) } } +/*class LoggerEmitter(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { + + companion object { + const val EVENT_NAME = "SDKLogEvent" + } + + override fun getName(): String { + return "LoggerEmitter" + } + + // Send logs to React Native + fun sendLog(logLevel: String, message: String) { + reactContext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) + .emit(EVENT_NAME, mapOf("logLevel" to logLevel, "message" to message)) + } +}*/ + private const val s = "Hello, Emit" class CustomerIOReactNativeLoggingWrapper private constructor( @@ -75,8 +96,17 @@ class CustomerIOReactNativeLoggingWrapper private constructor( private fun emit(message: String, level: CioLogLevel) { println("Hello, Emit!") if (shouldEmit(level)) { - val emitter = moduleRegistry.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) - emitter?.sendEvent(level.name, message) +// val emitter = moduleRegistry.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) +// emitter?.sendEvent(level.name, message) + + val data = buildMap { + put("logLevel", CioLogLevel.DEBUG) + put("message", message) + } + + moduleRegistry + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) + .emit("CioLogEvent", Arguments.makeNativeMap(data)) } } diff --git a/src/native-logger-listener.ts b/src/native-logger-listener.ts index 8dff5591..04ad5a7e 100644 --- a/src/native-logger-listener.ts +++ b/src/native-logger-listener.ts @@ -24,6 +24,7 @@ export class NativeLoggerListener { bridge.addListener( 'CioLogEvent', (event: { logLevel: CioLogLevel; message: string }) => { + console.log("I received the value here-->", event.message) // "someValue" // Using console.log will log to the JavaScript side but prevent // React Native’s default behavior of redirecting logs to the native side. // By doing it asynchronously, we ensure the logs are captured on both From 010c67d9f4c0af25f94b0d643ddc2e284aa21410 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:08:04 +0530 Subject: [PATCH 15/20] crash fix --- src/native-logger-listener.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/native-logger-listener.ts b/src/native-logger-listener.ts index 04ad5a7e..8dff5591 100644 --- a/src/native-logger-listener.ts +++ b/src/native-logger-listener.ts @@ -24,7 +24,6 @@ export class NativeLoggerListener { bridge.addListener( 'CioLogEvent', (event: { logLevel: CioLogLevel; message: string }) => { - console.log("I received the value here-->", event.message) // "someValue" // Using console.log will log to the JavaScript side but prevent // React Native’s default behavior of redirecting logs to the native side. // By doing it asynchronously, we ensure the logs are captured on both From fbabbabda0a8086858ce5ba995e05220480bcced Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:10:21 +0530 Subject: [PATCH 16/20] cleanup and working --- .../logging/CustomerIOReactNativeLogger.kt | 34 +++---------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index ae96e0ec..ea961716 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -34,6 +34,8 @@ class CustomerIOReactNativeLoggingEmitter( listenerCount -= count } + // Not in use currently, check if we need it or not + // If not then remove EVENT_NAME as well fun sendEvent(eventName: String, params: String) { println("I got control here") reactContext @@ -42,26 +44,6 @@ class CustomerIOReactNativeLoggingEmitter( } } -/*class LoggerEmitter(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { - - companion object { - const val EVENT_NAME = "SDKLogEvent" - } - - override fun getName(): String { - return "LoggerEmitter" - } - - // Send logs to React Native - fun sendLog(logLevel: String, message: String) { - reactContext - .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) - .emit(EVENT_NAME, mapOf("logLevel" to logLevel, "message" to message)) - } -}*/ - -private const val s = "Hello, Emit" - class CustomerIOReactNativeLoggingWrapper private constructor( private var moduleRegistry: ReactApplicationContext, override var logLevel: CioLogLevel): Logger { @@ -74,33 +56,27 @@ class CustomerIOReactNativeLoggingWrapper private constructor( } } -// fun setLogLevel(level: CioLogLevel) { -// logLevel = level -// } - override fun debug(message: String) { println("Hello, debug!") emit(message, CioLogLevel.DEBUG) } override fun info(message: String) { - println("Hello, debug!") + println("Hello, info!") emit(message, CioLogLevel.INFO) } override fun error(message: String) { - println("Hello, debug!") + println("Hello, error!") emit(message, CioLogLevel.ERROR) } private fun emit(message: String, level: CioLogLevel) { println("Hello, Emit!") if (shouldEmit(level)) { -// val emitter = moduleRegistry.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) -// emitter?.sendEvent(level.name, message) val data = buildMap { - put("logLevel", CioLogLevel.DEBUG) + put("logLevel", "info") put("message", message) } From f67ee3f9b9df21d9a19a8eb921ed1b6ab3fcfe90 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:14:52 +0530 Subject: [PATCH 17/20] fixed logger issue, now printing logs in JS --- .../sdk/logging/CustomerIOReactNativeLogger.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index ea961716..a5e94193 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -3,11 +3,13 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod +import com.facebook.react.bridge.WritableMap import com.facebook.react.module.annotations.ReactModule import com.facebook.react.modules.core.DeviceEventManagerModule import io.customer.sdk.core.util.CioLogLevel -import io.customer.sdk.core.util.Logger import kotlin.collections.buildMap +import io.customer.sdk.core.di.SDKComponent +import io.customer.sdk.core.util.Logger @ReactModule(name = CustomerIOReactNativeLoggingEmitter.NAME) class CustomerIOReactNativeLoggingEmitter( @@ -34,9 +36,7 @@ class CustomerIOReactNativeLoggingEmitter( listenerCount -= count } - // Not in use currently, check if we need it or not - // If not then remove EVENT_NAME as well - fun sendEvent(eventName: String, params: String) { + fun sendEvent(params: WritableMap) { println("I got control here") reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) @@ -48,10 +48,13 @@ class CustomerIOReactNativeLoggingWrapper private constructor( private var moduleRegistry: ReactApplicationContext, override var logLevel: CioLogLevel): Logger { + private val emitter: CustomerIOReactNativeLoggingEmitter? + get() = moduleRegistry?.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) + companion object { fun getInstance(moduleRegistry: ReactApplicationContext, logLevel: CioLogLevel): CustomerIOReactNativeLoggingWrapper { val instance = CustomerIOReactNativeLoggingWrapper(moduleRegistry, logLevel) -// DIGraphShared.shared.override(instance, CioLogger::class.java) + SDKComponent.overrideDependency(instance) return instance } } @@ -79,10 +82,7 @@ class CustomerIOReactNativeLoggingWrapper private constructor( put("logLevel", "info") put("message", message) } - - moduleRegistry - .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) - .emit("CioLogEvent", Arguments.makeNativeMap(data)) + emitter?.sendEvent(Arguments.makeNativeMap(data)) } } From 4e08e3077005cb7eb6636949e917f8162f76df87 Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:26:45 +0530 Subject: [PATCH 18/20] lateint to use CioLogLevel when and as received --- .../reactnative/sdk/CustomerIOReactNativeModule.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt index f0fd6538..5b7760d3 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt @@ -12,7 +12,6 @@ import io.customer.reactnative.sdk.logging.CustomerIOReactNativeLoggingWrapper import io.customer.reactnative.sdk.messagingpush.RNCIOPushMessaging import io.customer.sdk.CustomerIO import io.customer.sdk.CustomerIOBuilder -import io.customer.sdk.core.di.SDKComponent import io.customer.sdk.core.util.CioLogLevel import io.customer.sdk.core.util.Logger import io.customer.sdk.data.model.Region @@ -23,9 +22,7 @@ class NativeCustomerIOModule( private val pushMessagingModule: RNCIOPushMessaging, private val inAppMessagingModule: RNCIOInAppMessaging, ) : ReactContextBaseJavaModule(reactContext) { - private val logger: Logger - get() = CustomerIOReactNativeLoggingWrapper.getInstance(reactContext, CioLogLevel.DEBUG) - //SDKComponent.logger + private lateinit var logger: Logger // If the SDK is not initialized, `CustomerIO.instance()` throws an exception private val customerIOInstance: CustomerIO? @@ -47,6 +44,8 @@ class NativeCustomerIOModule( fun initialize( configJson: ReadableMap, logLevel: String) { + + logger = CustomerIOReactNativeLoggingWrapper.getInstance(reactContext, CioLogLevel.getLogLevel(logLevel)) val packageConfig = configJson.toMap() val cdpApiKey = packageConfig[Keys.Config.CDP_API_KEY] try { @@ -139,4 +138,4 @@ class NativeCustomerIOModule( companion object { internal const val MODULE_NAME = "NativeCustomerIO" } -} +} \ No newline at end of file From f384d5747b15b2d0fdf80861410405a97ca52eea Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:26:52 +0530 Subject: [PATCH 19/20] cleanup --- .../sdk/logging/CustomerIOReactNativeLogger.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index a5e94193..b6be3983 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -37,7 +37,6 @@ class CustomerIOReactNativeLoggingEmitter( } fun sendEvent(params: WritableMap) { - println("I got control here") reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) .emit(EVENT_NAME, params) @@ -60,26 +59,21 @@ class CustomerIOReactNativeLoggingWrapper private constructor( } override fun debug(message: String) { - println("Hello, debug!") emit(message, CioLogLevel.DEBUG) } override fun info(message: String) { - println("Hello, info!") emit(message, CioLogLevel.INFO) } override fun error(message: String) { - println("Hello, error!") emit(message, CioLogLevel.ERROR) } private fun emit(message: String, level: CioLogLevel) { - println("Hello, Emit!") if (shouldEmit(level)) { - val data = buildMap { - put("logLevel", "info") + put("logLevel", level.name.lowercase()) put("message", message) } emitter?.sendEvent(Arguments.makeNativeMap(data)) @@ -87,7 +81,6 @@ class CustomerIOReactNativeLoggingWrapper private constructor( } private fun shouldEmit(level: CioLogLevel): Boolean { - println("Hello, shouldEmit!") return when (logLevel) { CioLogLevel.NONE -> false CioLogLevel.ERROR -> level == CioLogLevel.ERROR @@ -95,5 +88,4 @@ class CustomerIOReactNativeLoggingWrapper private constructor( CioLogLevel.DEBUG -> true } } - } \ No newline at end of file From 50f95d6619a1039f31ddae777654416e4f77aa2f Mon Sep 17 00:00:00 2001 From: ami-aman <91549653+ami-aman@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:12:08 +0530 Subject: [PATCH 20/20] pr suggestion --- .../logging/CustomerIOReactNativeLogger.kt | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt index b6be3983..885eefad 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/logging/CustomerIOReactNativeLogger.kt @@ -44,31 +44,23 @@ class CustomerIOReactNativeLoggingEmitter( } class CustomerIOReactNativeLoggingWrapper private constructor( - private var moduleRegistry: ReactApplicationContext, + private var reactContext: ReactApplicationContext, override var logLevel: CioLogLevel): Logger { private val emitter: CustomerIOReactNativeLoggingEmitter? - get() = moduleRegistry?.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) + get() = reactContext?.getNativeModule(CustomerIOReactNativeLoggingEmitter::class.java) companion object { - fun getInstance(moduleRegistry: ReactApplicationContext, logLevel: CioLogLevel): CustomerIOReactNativeLoggingWrapper { - val instance = CustomerIOReactNativeLoggingWrapper(moduleRegistry, logLevel) - SDKComponent.overrideDependency(instance) - return instance + fun getInstance(reactContext: ReactApplicationContext, logLevel: CioLogLevel): CustomerIOReactNativeLoggingWrapper { + return CustomerIOReactNativeLoggingWrapper(reactContext, logLevel).also { + SDKComponent.overrideDependency(it) + } } } - override fun debug(message: String) { - emit(message, CioLogLevel.DEBUG) - } - - override fun info(message: String) { - emit(message, CioLogLevel.INFO) - } - - override fun error(message: String) { - emit(message, CioLogLevel.ERROR) - } + override fun debug(message: String) = emit(message, CioLogLevel.DEBUG) + override fun info(message: String) = emit(message, CioLogLevel.INFO) + override fun error(message: String) = emit(message, CioLogLevel.ERROR) private fun emit(message: String, level: CioLogLevel) { if (shouldEmit(level)) {