Skip to content

Commit

Permalink
fix: pass env param to log functions (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
surekhaw authored Mar 19, 2024
1 parent 83557df commit 610d9e3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Sources/PayPalMessages/IO/MerchantProfileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class MerchantProfileProvider: MerchantProfileHashGetable {
) { [weak self] result in
switch result {
case .success(let merchantProfileData):
log(.debug, "Merchant Request Hash succeeded with \(merchantProfileData.hash)")
log(.debug, "Merchant Request Hash succeeded with \(merchantProfileData.hash)", for: environment)
self?.setCachedMerchantProfileData(merchantProfileData, clientID: clientID, merchantID: merchantID)
onCompletion(merchantProfileData)

case .failure(let error):
log(.debug, "Merchant Request Hash failed with \(error.localizedDescription)")
log(.debug, "Merchant Request Hash failed with \(error.localizedDescription)", for: environment)
onCompletion(nil)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PayPalMessages/IO/MerchantProfileRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MerchantProfileRequest: MerchantProfileRequestable {
return
}

log(.debug, "fetcheMerchantProfile URL is \(url)")
log(.debug, "fetcheMerchantProfile URL is \(url)", for: environment)

fetch(url, headers: headers, session: environment.urlSession) { data, _, error in
guard let data = data, error == nil else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PayPalMessages/IO/MessageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MessageRequest: MessageRequestable {
}
let startingTimestamp = Date()

log(.debug, "fetchMessage URL is \(url)")
log(.debug, "fetchMessage URL is \(url)", for: parameters.environment)

fetch(url, headers: headers, session: parameters.environment.urlSession) { data, response, _ in
let requestDuration = startingTimestamp.timeIntervalSinceNow
Expand Down
4 changes: 2 additions & 2 deletions Sources/PayPalMessages/PayPalMessageModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ final class PayPalMessageModal: UIViewController, WKUIDelegate {
}

guard let presentingViewController = UIViewController.getPresentingViewController() else {
log(.error, "Unable to retrieve presenting view controller")
log(.error, "Unable to retrieve presenting view controller", for: environment)
return
}

if presentingViewController == self {
log(.warn, "Modal is already presenting")
log(.warn, "Modal is already presenting", for: environment)
return
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/PayPalMessages/PayPalMessageModalViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa

loadCompletionHandler = completionHandler

log(.debug, "Load modal webview URL: \(safeUrl)")
log(.debug, "Load modal webview URL: \(safeUrl)", for: environment)

webView.load(URLRequest(url: safeUrl))
}
Expand Down Expand Up @@ -207,7 +207,7 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
guard let jsonData = try? JSONEncoder().encode(self.makeConfig()),
let jsonString = String(data: jsonData, encoding: .utf8) else { return }

log(.debug, "Update props: \(jsonString)")
log(.debug, "Update props: \(jsonString)", for: environment)

self.webView.evaluateJavaScript(
"window.actions.updateProps(\(jsonString))"
Expand All @@ -227,11 +227,11 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
let json = try? JSONSerialization.jsonObject(with: bodyData) as? [String: Any],
let eventName = json["name"] as? String,
var eventArgs = json["args"] as? [[String: Any]] else {
log(.error, "Unable to parse modal event body")
log(.error, "Unable to parse modal event body", for: environment)
return
}

log(.debug, "Modal event: [\(eventName)] \(eventArgs)")
log(.debug, "Modal event: [\(eventName)] \(eventArgs)", for: environment)

guard !eventArgs.isEmpty else { return }

Expand Down
2 changes: 1 addition & 1 deletion Sources/PayPalMessages/PayPalMessageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class PayPalMessageViewModel: PayPalMessageModalEventDelegate {
modal.setConfig(makeModalConfig())
}

log(.debug, "onMessageRequestReceived is \(String(describing: response.defaultMainContent))")
log(.debug, "onMessageRequestReceived is \(String(describing: response.defaultMainContent))", for: environment)
}

// MARK: - Message Request Builder
Expand Down
2 changes: 1 addition & 1 deletion Sources/PayPalMessages/Utils/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum LogLevel: Int {
case error
}

func log(_ level: LogLevel, _ message: String, with data: Data? = nil, for environment: Environment = .live) {
func log(_ level: LogLevel, _ message: String, with data: Data? = nil, for environment: Environment) {
if level == .debug && environment.isProduction {
return
}
Expand Down

0 comments on commit 610d9e3

Please sign in to comment.