Skip to content

Commit

Permalink
Merge pull request #10446 from keymanapp/chore/ios/8737-remove-xcglogger
Browse files Browse the repository at this point in the history
chore(ios): eliminate xcglogger dependency
  • Loading branch information
sgschantz authored Jan 29, 2024
2 parents d4f8162 + 0d6facb commit 2ede490
Show file tree
Hide file tree
Showing 63 changed files with 736 additions and 497 deletions.
1 change: 0 additions & 1 deletion ios/Cartfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
github "weichsel/ZIPFoundation" ~> 0.9
github "keymanapp/dependency-XCGLogger" "master"
github "devicekit/DeviceKit" ~> 5.0
github "ashleymills/Reachability.swift"
github "getsentry/sentry-cocoa" ~> 8.7.0
1 change: 0 additions & 1 deletion ios/Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
github "ashleymills/Reachability.swift" "v5.1.0"
github "devicekit/DeviceKit" "5.1.0"
github "getsentry/sentry-cocoa" "8.15.2"
github "keymanapp/dependency-XCGLogger" "57a7b975dbb6fe4fe90cef3d1bc52b8adbd89113"
github "weichsel/ZIPFoundation" "0.9.17"
16 changes: 4 additions & 12 deletions ios/engine/KMEI/KeymanEngine.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
1645D5972036C9F80076C51B /* KMPKeyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1645D5962036C9F80076C51B /* KMPKeyboard.swift */; };
165EB3A12098993900040A69 /* KeyboardError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165EB3A02098993900040A69 /* KeyboardError.swift */; };
296EF2C72AFA26C700E3E384 /* ZIPFoundation.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 296EF2C62AFA26C700E3E384 /* ZIPFoundation.xcframework */; };
29B30C232B564F9900C342A4 /* KeymanEngineLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B30C222B564F9900C342A4 /* KeymanEngineLogger.swift */; };
377D10DE26846B8900467431 /* SpacebarTextViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 377D10DD26846B8900467431 /* SpacebarTextViewController.swift */; };
6CD5DFAA150F6DC8007A5DDE /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CD5DFA8150F6DC8007A5DDE /* icon.png */; };
6CD5DFAB150F6DC8007A5DDE /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 6CD5DFA9150F6DC8007A5DDE /* [email protected] */; };
Expand Down Expand Up @@ -70,7 +71,6 @@
C0452BAD1F9F21270064431A /* Keyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0452BAC1F9F21270064431A /* Keyboard.swift */; };
C0452BAF1F9F22A80064431A /* Font.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0452BAE1F9F22A80064431A /* Font.swift */; };
C055E6EB1F99ED090035C2DD /* RegisteredFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = C055E6EA1F99ED090035C2DD /* RegisteredFont.swift */; };
C05B14331FD914870082A316 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05B14321FD914870082A316 /* Log.swift */; };
C05F43311FBD62550058CBD4 /* JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05F43301FBD62550058CBD4 /* JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift */; };
C06085B41F9485E40057E5B9 /* UIButton+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06085B31F9485E40057E5B9 /* UIButton+Helpers.swift */; };
C06D37341F81F5C300F61AE0 /* HTTPDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0ED71B41F6BBFAF002A2FD6 /* HTTPDownloader.swift */; };
Expand Down Expand Up @@ -121,10 +121,8 @@
CE46D65D247B93C9005FD506 /* (null) in Resources */ = {isa = PBXBuildFile; };
CE5C8BE324B5B3BA00FAFB7F /* Queries+LexicalModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5C8BE224B5B3BA00FAFB7F /* Queries+LexicalModel.swift */; };
CE5C8BE524B5BD1C00FAFB7F /* QueryModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5C8BE424B5BD1C00FAFB7F /* QueryModelTests.swift */; };
CE5EDDC526522EAA001733AC /* XCGLogger.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE5EDDC026522EA9001733AC /* XCGLogger.xcframework */; };
CE5EDDC726522EAA001733AC /* Sentry.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE5EDDC226522EAA001733AC /* Sentry.xcframework */; };
CE5EDDC826522EAA001733AC /* Reachability.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE5EDDC326522EAA001733AC /* Reachability.xcframework */; };
CE5EDDC926522EAA001733AC /* ObjcExceptionBridging.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE5EDDC426522EAA001733AC /* ObjcExceptionBridging.xcframework */; };
CE5EDDD52652372A001733AC /* DeviceKit.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE5EDDBB26522EA3001733AC /* DeviceKit.xcframework */; };
CE67D961228A6F190029F2B5 /* KeyboardCommandStructs.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE67D960228A6F190029F2B5 /* KeyboardCommandStructs.swift */; };
CE71705823A9C14D00A924A1 /* ResourceFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE71705723A9C14D00A924A1 /* ResourceFileManager.swift */; };
Expand Down Expand Up @@ -327,6 +325,7 @@
29B27FEF29062CF50036917E /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/ResourceInfoView.strings; sourceTree = "<group>"; };
29B27FF029062D100036917E /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = "<group>"; };
29B27FF129062D190036917E /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = nl; path = nl.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
29B30C222B564F9900C342A4 /* KeymanEngineLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeymanEngineLogger.swift; sourceTree = "<group>"; };
29BFA75E28293287009FCCC3 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/ResourceInfoView.strings; sourceTree = "<group>"; };
29BFA75F282934B4009FCCC3 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = "<group>"; };
29BFA760282934BB009FCCC3 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = it; path = it.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
Expand Down Expand Up @@ -391,7 +390,6 @@
C0452BAC1F9F21270064431A /* Keyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keyboard.swift; sourceTree = "<group>"; };
C0452BAE1F9F22A80064431A /* Font.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Font.swift; sourceTree = "<group>"; };
C055E6EA1F99ED090035C2DD /* RegisteredFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisteredFont.swift; sourceTree = "<group>"; };
C05B14321FD914870082A316 /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
C05F43301FBD62550058CBD4 /* JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSONDecoder.DateDecodingStrategy+ISO8601Fallback.swift"; sourceTree = "<group>"; };
C06085B31F9485E40057E5B9 /* UIButton+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Helpers.swift"; sourceTree = "<group>"; };
C06D372B1F81F4E100F61AE0 /* KeymanEngine.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KeymanEngine.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -436,10 +434,8 @@
CE5C8BE224B5B3BA00FAFB7F /* Queries+LexicalModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Queries+LexicalModel.swift"; sourceTree = "<group>"; };
CE5C8BE424B5BD1C00FAFB7F /* QueryModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryModelTests.swift; sourceTree = "<group>"; };
CE5EDDBB26522EA3001733AC /* DeviceKit.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = DeviceKit.xcframework; path = ../../Carthage/Build/DeviceKit.xcframework; sourceTree = "<group>"; };
CE5EDDC026522EA9001733AC /* XCGLogger.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = XCGLogger.xcframework; path = ../../Carthage/Build/XCGLogger.xcframework; sourceTree = "<group>"; };
CE5EDDC226522EAA001733AC /* Sentry.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Sentry.xcframework; path = ../../Carthage/Build/Sentry.xcframework; sourceTree = "<group>"; };
CE5EDDC326522EAA001733AC /* Reachability.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Reachability.xcframework; path = ../../Carthage/Build/Reachability.xcframework; sourceTree = "<group>"; };
CE5EDDC426522EAA001733AC /* ObjcExceptionBridging.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = ObjcExceptionBridging.xcframework; path = ../../Carthage/Build/ObjcExceptionBridging.xcframework; sourceTree = "<group>"; };
CE67D960228A6F190029F2B5 /* KeyboardCommandStructs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardCommandStructs.swift; sourceTree = "<group>"; };
CE71705723A9C14D00A924A1 /* ResourceFileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceFileManager.swift; sourceTree = "<group>"; };
CE71705E23A9C97F00A924A1 /* PackageInstallViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageInstallViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -561,11 +557,9 @@
buildActionMask = 2147483647;
files = (
296EF2C72AFA26C700E3E384 /* ZIPFoundation.xcframework in Frameworks */,
CE5EDDC526522EAA001733AC /* XCGLogger.xcframework in Frameworks */,
CE5EDDD52652372A001733AC /* DeviceKit.xcframework in Frameworks */,
CE5EDDC726522EAA001733AC /* Sentry.xcframework in Frameworks */,
CE5EDDC826522EAA001733AC /* Reachability.xcframework in Frameworks */,
CE5EDDC926522EAA001733AC /* ObjcExceptionBridging.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -950,10 +944,8 @@
isa = PBXGroup;
children = (
296EF2C62AFA26C700E3E384 /* ZIPFoundation.xcframework */,
CE5EDDC426522EAA001733AC /* ObjcExceptionBridging.xcframework */,
CE5EDDC326522EAA001733AC /* Reachability.xcframework */,
CE5EDDC226522EAA001733AC /* Sentry.xcframework */,
CE5EDDC026522EA9001733AC /* XCGLogger.xcframework */,
CE5EDDBB26522EA3001733AC /* DeviceKit.xcframework */,
9A079DE52231A69D00581263 /* Foundation.framework */,
);
Expand Down Expand Up @@ -1000,10 +992,10 @@
CE7A26DA23CEEF640005955C /* Colors.swift */,
CE7A26D723CEEC630005955C /* Colors+Extension.swift */,
C0959CD31F99C44E00B616BC /* Constants.swift */,
29B30C222B564F9900C342A4 /* KeymanEngineLogger.swift */,
CEE0321224C58C90005BFC73 /* KeymanHosts.swift */,
C0324B921F87689B00AF3785 /* KeymanURLProtocol.swift */,
C0A93A531F8B21240079948B /* Manager.swift */,
C05B14321FD914870082A316 /* Log.swift */,
CEA70CCE24CAC3AE001C12E6 /* Obsoletions.swift */,
CE9E95CC24CE786900F6DD78 /* UniversalLinks.swift */,
);
Expand Down Expand Up @@ -1439,7 +1431,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C05B14331FD914870082A316 /* Log.swift in Sources */,
9A079E43223B61AE00581263 /* FullLexicalModelID.swift in Sources */,
C06D37341F81F5C300F61AE0 /* HTTPDownloader.swift in Sources */,
C0452BAF1F9F22A80064431A /* Font.swift in Sources */,
Expand Down Expand Up @@ -1525,6 +1516,7 @@
C06085B41F9485E40057E5B9 /* UIButton+Helpers.swift in Sources */,
C0959CD41F99C44E00B616BC /* Constants.swift in Sources */,
C0452BAD1F9F21270064431A /* Keyboard.swift in Sources */,
29B30C232B564F9900C342A4 /* KeymanEngineLogger.swift in Sources */,
CE79B24923C711FF007E72AE /* KeyboardScaleMap.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
5 changes: 3 additions & 2 deletions ios/engine/KMEI/KeymanEngine/Classes/Alerts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import UIKit
import Reachability
import os.log

open class Alerts {
public typealias AcceptanceHandler = ((UIAlertAction)) -> Void
Expand Down Expand Up @@ -48,8 +49,8 @@ open class Alerts {
do {
try networkReachable = Reachability(hostname: KeymanHosts.KEYMAN_COM.host!)
} catch {
log.debug("reachability could not start")
}
os_log("Reachability could not start", log:KeymanEngineLogger.ui, type: .debug)
}

if networkReachable?.connection == Reachability.Connection.unavailable || networkReachable == nil {
showConnectionErrorAlert(in: vc, handler: handler)
Expand Down
79 changes: 18 additions & 61 deletions ios/engine/KMEI/KeymanEngine/Classes/Errors/SentryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Foundation
import XCGLogger
import Sentry
import os.log

/**
* This class centralizes the methods used among the KeymanEngine library, Keyman app, and SWKeyboard app-ex for Sentry-based
Expand All @@ -26,10 +26,10 @@ public class SentryManager {
#if NO_SENTRY
// If doing development debugging (and NOT for Sentry code), silence Sentry reporting.
let allowEnabled = false
log.debug("Sentry error logging disabled for development mode.")
os_log("Sentry error logging disabled for development mode.", log: KeymanEngineLogger.settings, type: .debug)
#else
let allowEnabled = true
log.debug("Sentry error logging enabled.")
os_log("Sentry error logging enabled.", log: KeymanEngineLogger.settings, type: .debug)
#endif

let infoDict = Bundle(for: SentryManager.self).infoDictionary
Expand Down Expand Up @@ -90,106 +90,63 @@ public class SentryManager {
#endif
}

private static func mapLoggingLevel(_ level: Sentry.SentryLevel) -> XCGLogger.Level {
switch(level) {
case .none:
return XCGLogger.Level.none
case .debug:
return .debug
case .info:
return .info
case .warning:
return .warning
case .error:
return .error
case .fatal:
return .severe
default:
return .info
}
}

/**
* Captures a Sentry event and copies its message to the engine's logging mechanism.
* If the logging level is not specified, the Sentry event's log-level will be used as a default.
*
* Will safely bypass the Sentry component if not activated by the app, only logging the
* message in such scenarios.
* Captures a Sentry event and safely bypass the Sentry component if not activated by the app.
*/
public static func captureAndLog(_ event: Sentry.Event, logLevel: XCGLogger.Level? = nil) {
public static func capture(_ event: Sentry.Event) {
// Guarded in case a library consumer decides against initializing Sentry.
if _started {
SentrySDK.capture(event: event)
}

let level = logLevel ?? mapLoggingLevel(event.level)
log.logln(event.message?.formatted, level: level)
}

/**
* Captures a Sentry event and copies its message to the engine's logging mechanism.
* If the logging level is not specified, the Sentry event's log-level will be used as a default.
*
* Will safely bypass the Sentry component if not activated by the app, only logging the
* message in such scenarios.
* Captures a Sentry event for the specified error. If the logging level is not specified, it will default to .error.
* Will safely bypass the Sentry component if not activated by the app.
*/
public static func captureAndLog(_ error: Error, message: String? = nil, sentryLevel: Sentry.SentryLevel = .error, logLevel: XCGLogger.Level? = nil) {
public static func capture(_ error: Error, message: String? = nil, sentryLevel: Sentry.SentryLevel = .error) {
let event = Sentry.Event(error: error)
event.level = sentryLevel
if let message = message {
event.message = SentryMessage(formatted: message)
}

self.captureAndLog(event, logLevel: logLevel)
self.capture(event)
}

/**
* Constructs a SentryEvent around a message and also passes it to the engine's logging mechanism.
* If the logging level is not specified, it will default to .error.
*
* Will safely bypass the Sentry component if not activated by the app, only logging the
* message in such scenarios.
* Constructs a SentryEvent around a message. If the logging level is not specified, it will default to .error.
* Will safely bypass the Sentry component if not activated by the app.
*/
public static func captureAndLog(_ message: String, sentryLevel: Sentry.SentryLevel = .error, logLevel: XCGLogger.Level? = nil) {
public static func capture(_ message: String, sentryLevel: Sentry.SentryLevel = .error) {
let event = Sentry.Event(level: sentryLevel)
event.message = SentryMessage(formatted: message)

self.captureAndLog(event, logLevel: logLevel)
self.capture(event)
}

/**
* Adds a Sentry breadcrumb and copies its message to the engine's logging mechanism.
* If the logging level is not specified, the Sentry event's log-level will be used as a default.
*
* Will safely bypass the Sentry component if not activated by the app, only logging the
* message in such scenarios.
* Adds a Sentry breadcrumb. Will safely bypass the Sentry component if not activated by the app.
*/
public static func breadcrumbAndLog(crumb: Sentry.Breadcrumb, logLevel: XCGLogger.Level? = nil) {
public static func breadcrumb(crumb: Sentry.Breadcrumb) {
// Guarded in case a library consumer decides against initializing Sentry.
if _started {
SentrySDK.addBreadcrumb(crumb)
}

let level = logLevel ?? mapLoggingLevel(crumb.level)
log.logln(crumb.message, level: level)
}

/**
* Adds a Sentry breadcrumb and copies its message to the engine's logging mechanism.
* If the logging level is not specified, the Sentry event's log-level will be used as a default.
*
* Will safely bypass the Sentry component if not activated by the app, only logging the
* message in such scenarios.
* Adds a Sentry breadcrumb. Will safely bypass the Sentry component if not activated by the app.
*/
public static func breadcrumbAndLog(_ message: String, category: String? = nil, sentryLevel: Sentry.SentryLevel = .info, logLevel: XCGLogger.Level? = nil) {
public static func breadcrumb(_ message: String, category: String? = nil, sentryLevel: Sentry.SentryLevel = .info) {
let crumb = Sentry.Breadcrumb()
crumb.level = sentryLevel
if let category = category {
crumb.category = category
}
crumb.message = message

self.breadcrumbAndLog(crumb: crumb, logLevel: logLevel)
self.breadcrumb(crumb: crumb)
}

public static func forceError() {
Expand Down
Loading

0 comments on commit 2ede490

Please sign in to comment.