Skip to content

Commit

Permalink
chore: add production logs and refactor Logger (RMCCX-6877)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoumenRautray committed Aug 23, 2024
1 parent 98aecaf commit 9950e87
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Sources/RInAppMessaging/InAppMessagingModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ internal class InAppMessagingModule: ErrorDelegate, CampaignDispatcherDelegate,
checkUserChanges()
eventMatcher.matchAndStore(event: event)
campaignTriggerAgent.validateAndTriggerCampaigns()
Logger.debugLog("function: LogEvent")
return true
}

func registerPreference(_ preference: UserInfoProvider) {
Logger.debugLog("function: registerPreference")
accountRepository.setPreference(preference)

guard isInitialized else {
Expand All @@ -103,6 +105,7 @@ internal class InAppMessagingModule: ErrorDelegate, CampaignDispatcherDelegate,
}

func closeMessage(clearQueuedCampaigns: Bool) {
Logger.debugLog("function: closeMessage")
if clearQueuedCampaigns {
readyCampaignDispatcher.resetQueue()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/RInAppMessaging/Protocols/HttpRequestable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ extension HttpRequestable {

if let error = error {
completion(.failure(.taskFailed(error)))
Logger.debug(error)
Logger.debug("Error: \(error)")
return
}

Expand Down
1 change: 1 addition & 0 deletions Sources/RInAppMessaging/RInAppMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import RSDKUtils
let validConfigURL = tryGettingValidConfigURL(config)
let mainContainer = MainContainerFactory.create(dependencyManager: dependencyManager, configURL: validConfigURL)
dependencyManager.appendContainer(mainContainer)
Logger.debugLog("function: Configure")
configure(dependencyManager: dependencyManager, moduleConfig: config)
}

Expand Down
14 changes: 0 additions & 14 deletions Sources/RInAppMessaging/Utilities/CommonUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,3 @@ internal struct CommonUtility {
return nil
}
}

internal enum Logger {
static func debug(_ value: Any) {
#if DEBUG
print("InAppMessaging: " + String(describing: value))
#endif
}

static func debug(_ message: String) {
#if DEBUG
print("InAppMessaging: " + message)
#endif
}
}
30 changes: 30 additions & 0 deletions Sources/RInAppMessaging/Utilities/Logger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import Foundation

extension OSLog {
static let sdk = OSLog(category: "RInAppMessaging SDK")

Check notice

Code scanning / mobsfscan

The App logs information. Sensitive information should never be logged. Note

The App logs information. Sensitive information should never be logged.

private convenience init(category: String, bundle: Bundle = Bundle(for: Logger.self)) {
let identifier = bundle.infoDictionary?["CFBundleIdentifier"] as? String
self.init(subsystem: (identifier ?? "").appending(".logs"), category: category)
}
}

class Logger {
// Debug Logging
class func debug(_ message: String) {
#if DEBUG
print("InAppMessaging: " + message)
#else
os_log("%s", log: OSLog.sdk, type: .error, message)
#endif
}

class func debugLog(_ message: String) {
#if DEBUG
// do nothing
#else
os_log("%s", log: OSLog.sdk, type: .error, message)
#endif
}
}

0 comments on commit 9950e87

Please sign in to comment.