From c9a8e9cd4a35c325d67383bff19b563c150d6462 Mon Sep 17 00:00:00 2001 From: Rui <102453770+ruixhuang@users.noreply.github.com> Date: Tue, 14 May 2024 13:22:55 -0700 Subject: [PATCH] MOB-486 iOS: Log error into Crashlytics (#167) --- .../CrashlyticsErrorLogging.swift | 9 +++++++++ .../_Error/_Log/CompositeErrorLogging.swift | 12 +++++++++++ .../_Error/_Log/DebugErrorLogging.swift | 8 ++++++++ .../_Error/_Log/ErrorLogging.swift | 3 ++- Utilities/Utilities.xcodeproj/project.pbxproj | 12 +++++++++++ Utilities/Utilities/_Logging/Logging.swift | 14 +++++++++++++ .../project.pbxproj | 4 ++++ .../AbacusLoggingImp.swift | 20 +++++++++++++++++++ .../Implementations.swift | 3 ++- 9 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Utilities/Utilities/_Logging/Logging.swift create mode 100644 dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/AbacusLoggingImp.swift diff --git a/FirebaseStaticInjections/FirebaseStaticInjections/_ErrorLogging/CrashlyticsErrorLogging.swift b/FirebaseStaticInjections/FirebaseStaticInjections/_ErrorLogging/CrashlyticsErrorLogging.swift index a6c844550..560a55b74 100644 --- a/FirebaseStaticInjections/FirebaseStaticInjections/_ErrorLogging/CrashlyticsErrorLogging.swift +++ b/FirebaseStaticInjections/FirebaseStaticInjections/_ErrorLogging/CrashlyticsErrorLogging.swift @@ -18,4 +18,13 @@ public class CrashlyticsErrorLogging: NSObject & ErrorLoggingProtocol { Crashlytics.crashlytics().record(error: error) } } + + public func e(tag: String, message: String) { + Crashlytics.crashlytics().record(error: NSError(domain: tag, code: 0, userInfo: [NSLocalizedDescriptionKey: message])) + } + + public func d(tag: String, message: String) { + // Do nothing + } + } diff --git a/ParticlesKit/ParticlesKit/_Error/_Log/CompositeErrorLogging.swift b/ParticlesKit/ParticlesKit/_Error/_Log/CompositeErrorLogging.swift index b7c4d9719..bb7683c2e 100644 --- a/ParticlesKit/ParticlesKit/_Error/_Log/CompositeErrorLogging.swift +++ b/ParticlesKit/ParticlesKit/_Error/_Log/CompositeErrorLogging.swift @@ -22,4 +22,16 @@ public class CompositeErrorLogging: NSObject & ErrorLoggingProtocol { logging.log(error) } } + + public func e(tag: String, message: String) { + for logging in loggings { + logging.e(tag: tag, message: message) + } + } + + public func d(tag: String, message: String) { + for logging in loggings { + logging.d(tag: tag, message: message) + } + } } diff --git a/ParticlesKit/ParticlesKit/_Error/_Log/DebugErrorLogging.swift b/ParticlesKit/ParticlesKit/_Error/_Log/DebugErrorLogging.swift index 53d4533f8..b6b4e8742 100644 --- a/ParticlesKit/ParticlesKit/_Error/_Log/DebugErrorLogging.swift +++ b/ParticlesKit/ParticlesKit/_Error/_Log/DebugErrorLogging.swift @@ -9,6 +9,14 @@ import Utilities public class DebugErrorLogging: NSObject & ErrorLoggingProtocol { + public func e(tag: String, message: String) { + Console.shared.log("Error: \(tag) \(message)") + } + + public func d(tag: String, message: String) { + Console.shared.log("Debug: \(tag) \(message)") + } + public func log(_ error: Error?) { if let error = error { Console.shared.log("Error:\(error)") diff --git a/ParticlesKit/ParticlesKit/_Error/_Log/ErrorLogging.swift b/ParticlesKit/ParticlesKit/_Error/_Log/ErrorLogging.swift index 480f1a9e8..da6f32712 100644 --- a/ParticlesKit/ParticlesKit/_Error/_Log/ErrorLogging.swift +++ b/ParticlesKit/ParticlesKit/_Error/_Log/ErrorLogging.swift @@ -7,8 +7,9 @@ // import Foundation +import Utilities -public protocol ErrorLoggingProtocol: NSObjectProtocol { +public protocol ErrorLoggingProtocol: NSObjectProtocol, Logging { func log(_ error: Error?) } diff --git a/Utilities/Utilities.xcodeproj/project.pbxproj b/Utilities/Utilities.xcodeproj/project.pbxproj index da202ae92..2320e8af8 100644 --- a/Utilities/Utilities.xcodeproj/project.pbxproj +++ b/Utilities/Utilities.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 0253CEC42AA009D70033F064 /* DebugEnabled.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0253CEC32AA009D70033F064 /* DebugEnabled.swift */; }; 025B752B28A703E800A4AC98 /* ObjectLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 025B752A28A703E800A4AC98 /* ObjectLoader.swift */; }; 025B752D28A7041600A4AC98 /* ClassLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 025B752C28A7041600A4AC98 /* ClassLoader.swift */; }; + 026734EC2BF2B6BB00DBF51A /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 026734EB2BF2B6BB00DBF51A /* Logging.swift */; }; 027E1EE329CA0F790098666F /* KeyValueStoreProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027E1EE229CA0F790098666F /* KeyValueStoreProtocol.swift */; }; 027E1EE529CA100B0098666F /* UserDefaultsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027E1EE429CA100B0098666F /* UserDefaultsStore.swift */; }; 027E1EE929CA1E7A0098666F /* SettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027E1EE829CA1E7A0098666F /* SettingsStore.swift */; }; @@ -288,6 +289,7 @@ 0253CEC32AA009D70033F064 /* DebugEnabled.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugEnabled.swift; sourceTree = ""; }; 025B752A28A703E800A4AC98 /* ObjectLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectLoader.swift; sourceTree = ""; }; 025B752C28A7041600A4AC98 /* ClassLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassLoader.swift; sourceTree = ""; }; + 026734EB2BF2B6BB00DBF51A /* Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = ""; }; 027E1EE229CA0F790098666F /* KeyValueStoreProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyValueStoreProtocol.swift; sourceTree = ""; }; 027E1EE429CA100B0098666F /* UserDefaultsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsStore.swift; sourceTree = ""; }; 027E1EE829CA1E7A0098666F /* SettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsStore.swift; sourceTree = ""; }; @@ -469,6 +471,14 @@ path = _AsyncStep; sourceTree = ""; }; + 026734EA2BF2B69E00DBF51A /* _Logging */ = { + isa = PBXGroup; + children = ( + 026734EB2BF2B6BB00DBF51A /* Logging.swift */, + ); + path = _Logging; + sourceTree = ""; + }; 027E1EE129CA0F630098666F /* _Store */ = { isa = PBXGroup; children = ( @@ -849,6 +859,7 @@ 312CE38A2630A37400C519C0 /* _Javascript */, 314B63D623DCCF0100139EB3 /* _Localization */, 314B639D23DCCF0100139EB3 /* _Location */, + 026734EA2BF2B69E00DBF51A /* _Logging */, 314B638E23DCCF0100139EB3 /* _Map */, 3162C02624C378FD00DE648C /* _Notification */, 3162C00D24C3781D00DE648C /* _Permissions */, @@ -1375,6 +1386,7 @@ 314B63FC23DCCF0200139EB3 /* MapPoint.swift in Sources */, 314B64DC23DCCF0200139EB3 /* CompositeTracking.swift in Sources */, 3101F94A25112C5900AC4010 /* AuthService.swift in Sources */, + 026734EC2BF2B6BB00DBF51A /* Logging.swift in Sources */, 020F758E2988072800DA2D87 /* Combine+Ext.swift in Sources */, 3162C00624C377E000DE648C /* PrompterProtocol.swift in Sources */, 3162C01324C3784800DE648C /* PhotoAlbumsPermission.swift in Sources */, diff --git a/Utilities/Utilities/_Logging/Logging.swift b/Utilities/Utilities/_Logging/Logging.swift new file mode 100644 index 000000000..a26f656a7 --- /dev/null +++ b/Utilities/Utilities/_Logging/Logging.swift @@ -0,0 +1,14 @@ +// +// Logging.swift +// Utilities +// +// Created by Rui Huang on 13/05/2024. +// Copyright © 2024 dYdX Trading Inc. All rights reserved. +// + +import Foundation + +public protocol Logging { + func e(tag: String, message: String) + func d(tag: String, message: String) +} diff --git a/dydx/dydxStateManager/dydxStateManager.xcodeproj/project.pbxproj b/dydx/dydxStateManager/dydxStateManager.xcodeproj/project.pbxproj index f2175e625..1791845d9 100644 --- a/dydx/dydxStateManager/dydxStateManager.xcodeproj/project.pbxproj +++ b/dydx/dydxStateManager/dydxStateManager.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 0260351029EF3C2E00DFFD11 /* WalletSendTransactionStep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0260350F29EF3C2E00DFFD11 /* WalletSendTransactionStep.swift */; }; 02603B9129F1A95E00DFFD11 /* dydxClientState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02603B9029F1A95E00DFFD11 /* dydxClientState.swift */; }; 02603B9429F1A99D00DFFD11 /* dydxTransferState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02603B9329F1A99D00DFFD11 /* dydxTransferState.swift */; }; + 026734F22BF2BFCC00DBF51A /* AbacusLoggingImp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 026734F12BF2BFCC00DBF51A /* AbacusLoggingImp.swift */; }; 027CB28E29EF02C50069781A /* DepositTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027CB28D29EF02C50069781A /* DepositTransaction.swift */; }; 027CB29429EF035E0069781A /* DepositTransactionV4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027CB29329EF035E0069781A /* DepositTransactionV4.swift */; }; 027CB2A029EF04270069781A /* dydxCartera.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 027CB29B29EF04170069781A /* dydxCartera.framework */; }; @@ -142,6 +143,7 @@ 0260350F29EF3C2E00DFFD11 /* WalletSendTransactionStep.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletSendTransactionStep.swift; sourceTree = ""; }; 02603B9029F1A95E00DFFD11 /* dydxClientState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxClientState.swift; sourceTree = ""; }; 02603B9329F1A99D00DFFD11 /* dydxTransferState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTransferState.swift; sourceTree = ""; }; + 026734F12BF2BFCC00DBF51A /* AbacusLoggingImp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AbacusLoggingImp.swift; sourceTree = ""; }; 027CB28D29EF02C50069781A /* DepositTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DepositTransaction.swift; sourceTree = ""; }; 027CB29329EF035E0069781A /* DepositTransactionV4.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DepositTransactionV4.swift; sourceTree = ""; }; 027CB29529EF04170069781A /* dydxCartera.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = dydxCartera.xcodeproj; path = ../dydxCartera/dydxCartera.xcodeproj; sourceTree = ""; }; @@ -356,6 +358,7 @@ 6473ACBF2A65B1FD00BBC01F /* AbacusFormatterImp.swift */, 6473AE402A65D3E700BBC01F /* AbacusChainImp.swift */, 646EE0842A75A8F4006A68E4 /* AbacusTimerImp.swift */, + 026734F12BF2BFCC00DBF51A /* AbacusLoggingImp.swift */, 646EDDEE2A732DBB006A68E4 /* Implementations.swift */, ); path = Protocol_Implementations; @@ -672,6 +675,7 @@ 0260351029EF3C2E00DFFD11 /* WalletSendTransactionStep.swift in Sources */, 023BFFD92ABBC4C000D3ED5C /* ERC20ApprovalStep.swift in Sources */, 02603B9429F1A99D00DFFD11 /* dydxTransferState.swift in Sources */, + 026734F22BF2BFCC00DBF51A /* AbacusLoggingImp.swift in Sources */, 022E928828EA4FD80096CDA9 /* Models+Ext.swift in Sources */, 027CB29429EF035E0069781A /* DepositTransactionV4.swift in Sources */, 646EDDEF2A732DBB006A68E4 /* Implementations.swift in Sources */, diff --git a/dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/AbacusLoggingImp.swift b/dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/AbacusLoggingImp.swift new file mode 100644 index 000000000..020f8a0b3 --- /dev/null +++ b/dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/AbacusLoggingImp.swift @@ -0,0 +1,20 @@ +// +// AbacusLoggingImp.swift +// dydxStateManager +// +// Created by Rui Huang on 13/05/2024. +// + +import Foundation +import Abacus +import ParticlesKit + +final public class AbacusLoggingImp: NSObject, Abacus.LoggingProtocol { + public func e(tag: String, message: String) { + ErrorLogging.shared?.e(tag: tag, message: message) + } + + public func d(tag: String, message: String) { + ErrorLogging.shared?.d(tag: tag, message: message) + } +} diff --git a/dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/Implementations.swift b/dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/Implementations.swift index bb7e39e78..1eef762ca 100644 --- a/dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/Implementations.swift +++ b/dydx/dydxStateManager/dydxStateManager/Protocol_Implementations/Implementations.swift @@ -6,6 +6,7 @@ // import Abacus +import ParticlesKit extension IOImplementations { public static let shared = IOImplementations(rest: AbacusRestImp(), @@ -15,7 +16,7 @@ extension IOImplementations { threading: AbacusThreadingImp(), timer: AbacusTimerImp(), fileSystem: AbacusFileSystemImp(), - logging: nil) + logging: AbacusLoggingImp()) } extension UIImplementations {