Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add production logs and refactor Logger (RMCCX-6877) #326

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading