Skip to content

Commit

Permalink
MOB-486 iOS: Log error into Crashlytics (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored and mike-dydx committed Aug 20, 2024
1 parent 31477db commit c9a8e9c
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
12 changes: 12 additions & 0 deletions ParticlesKit/ParticlesKit/_Error/_Log/CompositeErrorLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
8 changes: 8 additions & 0 deletions ParticlesKit/ParticlesKit/_Error/_Log/DebugErrorLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
3 changes: 2 additions & 1 deletion ParticlesKit/ParticlesKit/_Error/_Log/ErrorLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//

import Foundation
import Utilities

public protocol ErrorLoggingProtocol: NSObjectProtocol {
public protocol ErrorLoggingProtocol: NSObjectProtocol, Logging {
func log(_ error: Error?)
}

Expand Down
12 changes: 12 additions & 0 deletions Utilities/Utilities.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -288,6 +289,7 @@
0253CEC32AA009D70033F064 /* DebugEnabled.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugEnabled.swift; sourceTree = "<group>"; };
025B752A28A703E800A4AC98 /* ObjectLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectLoader.swift; sourceTree = "<group>"; };
025B752C28A7041600A4AC98 /* ClassLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassLoader.swift; sourceTree = "<group>"; };
026734EB2BF2B6BB00DBF51A /* Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
027E1EE229CA0F790098666F /* KeyValueStoreProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyValueStoreProtocol.swift; sourceTree = "<group>"; };
027E1EE429CA100B0098666F /* UserDefaultsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsStore.swift; sourceTree = "<group>"; };
027E1EE829CA1E7A0098666F /* SettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsStore.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -469,6 +471,14 @@
path = _AsyncStep;
sourceTree = "<group>";
};
026734EA2BF2B69E00DBF51A /* _Logging */ = {
isa = PBXGroup;
children = (
026734EB2BF2B6BB00DBF51A /* Logging.swift */,
);
path = _Logging;
sourceTree = "<group>";
};
027E1EE129CA0F630098666F /* _Store */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -849,6 +859,7 @@
312CE38A2630A37400C519C0 /* _Javascript */,
314B63D623DCCF0100139EB3 /* _Localization */,
314B639D23DCCF0100139EB3 /* _Location */,
026734EA2BF2B69E00DBF51A /* _Logging */,
314B638E23DCCF0100139EB3 /* _Map */,
3162C02624C378FD00DE648C /* _Notification */,
3162C00D24C3781D00DE648C /* _Permissions */,
Expand Down Expand Up @@ -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 */,
Expand Down
14 changes: 14 additions & 0 deletions Utilities/Utilities/_Logging/Logging.swift
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -142,6 +143,7 @@
0260350F29EF3C2E00DFFD11 /* WalletSendTransactionStep.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletSendTransactionStep.swift; sourceTree = "<group>"; };
02603B9029F1A95E00DFFD11 /* dydxClientState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxClientState.swift; sourceTree = "<group>"; };
02603B9329F1A99D00DFFD11 /* dydxTransferState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTransferState.swift; sourceTree = "<group>"; };
026734F12BF2BFCC00DBF51A /* AbacusLoggingImp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AbacusLoggingImp.swift; sourceTree = "<group>"; };
027CB28D29EF02C50069781A /* DepositTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DepositTransaction.swift; sourceTree = "<group>"; };
027CB29329EF035E0069781A /* DepositTransactionV4.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DepositTransactionV4.swift; sourceTree = "<group>"; };
027CB29529EF04170069781A /* dydxCartera.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = dydxCartera.xcodeproj; path = ../dydxCartera/dydxCartera.xcodeproj; sourceTree = "<group>"; };
Expand Down Expand Up @@ -356,6 +358,7 @@
6473ACBF2A65B1FD00BBC01F /* AbacusFormatterImp.swift */,
6473AE402A65D3E700BBC01F /* AbacusChainImp.swift */,
646EE0842A75A8F4006A68E4 /* AbacusTimerImp.swift */,
026734F12BF2BFCC00DBF51A /* AbacusLoggingImp.swift */,
646EDDEE2A732DBB006A68E4 /* Implementations.swift */,
);
path = Protocol_Implementations;
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Abacus
import ParticlesKit

extension IOImplementations {
public static let shared = IOImplementations(rest: AbacusRestImp(),
Expand All @@ -15,7 +16,7 @@ extension IOImplementations {
threading: AbacusThreadingImp(),
timer: AbacusTimerImp(),
fileSystem: AbacusFileSystemImp(),
logging: nil)
logging: AbacusLoggingImp())
}

extension UIImplementations {
Expand Down

0 comments on commit c9a8e9c

Please sign in to comment.