taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit a1125aba50e30eb8d0cd46b9aac1019a9fd55f73
parent fbb3468dce33f4c86d2b6fc9939d1f3ff9c7f136
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 22 Dec 2025 16:01:37 +0100

Logging

Diffstat:
MTalerWallet1/Backend/WalletCore.swift | 24++++++++++++++++++++----
MTalerWallet1/Views/Settings/SettingsView.swift | 8++++++++
2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/TalerWallet1/Backend/WalletCore.swift b/TalerWallet1/Backend/WalletCore.swift @@ -36,6 +36,7 @@ class WalletCore: QuickjsMessageHandler { var developDelay: Bool? // if set in SettingsView will delay wallet-core after each action var isObserving: Int var isLogging: Bool + var logTransactions: Bool let logger = Logger(subsystem: "net.taler.gnu", category: "WalletCore") private var expired: [String] = [] // save txID of expired items to not beep twice @@ -89,6 +90,7 @@ class WalletCore: QuickjsMessageHandler { init() throws { isObserving = 0 isLogging = false + logTransactions = false // logger.trace("init Quickjs") requestsMade = 0 queue = DispatchQueue(label: "net.taler.myQueue", attributes: .concurrent) @@ -129,7 +131,7 @@ extension WalletCore { } } - private func handleResponse(_ decoded: ResponseOrNotification, _ message: String?) throws { + private func handleResponse(_ decoded: ResponseOrNotification, _ message: String) throws { guard let requestId = decoded.id else { logger.error("didn't find requestId in response") symLog.log(decoded) // TODO: .error @@ -146,7 +148,15 @@ extension WalletCore { } do { let jsonData = try JSONEncoder().encode(result) -// symLog.log("\"id\":\(requestId) \(result)") + if let operation = decoded.operation { + if operation == "getTransactionsV2" { + if logTransactions { + symLog.log(message) + } + } else { + symLog.log(message) + } + } // logger.info(result) TODO: log result completion(requestId, timeSent, message, jsonData, nil) } catch { // JSON encoding of response.result failed / should never happen @@ -431,7 +441,7 @@ extension WalletCore { symLog.log("\"id\":\(decoded.id ?? 0) \(message)") try handleError(decoded, message) case "response": - symLog.log(message) +// symLog.log(message) try handleResponse(decoded, message) case "notification": // symLog.log(message) @@ -477,7 +487,13 @@ extension WalletCore { self.semaphore.signal() // free requestsMade let args = try JSONEncoder().encode(request.args) if let jsonArgs = String(data: args, encoding: .utf8) { - self.logger.log("🔴\"id\":\(requestId, privacy: .public) \(request.operation, privacy: .public)\(jsonArgs, privacy: .auto)") + if request.operation == "getTransactionsV2" { + if self.logTransactions { + self.logger.trace("🔴\"id\":\(requestId, privacy: .public) \(request.operation, privacy: .public)\(jsonArgs, privacy: .auto)") + } + } else { + self.logger.log("🔴\"id\":\(requestId, privacy: .public) \(request.operation, privacy: .public)\(jsonArgs, privacy: .auto)") + } } else { // should NEVER happen since the whole request was already successfully encoded and stringified self.logger.log("🔴\"id\":\(requestId, privacy: .public) \(request.operation, privacy: .public) 🔴 Error: jsonArgs") } diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift @@ -33,6 +33,7 @@ struct SettingsView: View { #else @AppStorage("developerMode") var developerMode: Bool = false #endif + @AppStorage("logTransactions") var logTransactions: Bool = false @AppStorage("useHaptics") var useHaptics: Bool = true @AppStorage("playSoundsI") var playSoundsI: Int = 1 @AppStorage("playSoundsB") var playSoundsB: Bool = false @@ -91,6 +92,13 @@ struct SettingsView: View { let walletCore = WalletCore.shared Group { List { +#if DEBUG + if showDevelopItems { + SettingsToggle(name: String("Log Transactions"), value: $logTransactions.onChange({ isLogging in + walletCore.logTransactions = isLogging}), id1: "logTransactions", + description: hideDescriptions ? nil : String("full log with all tx")) {} + } +#endif #if TALER_WALLET let appName = "Taler Wallet" #elseif TALER_NIGHTLY