Merge pull request #4500 from keymanapp/fix/ios/system-logs

fix(ios): app logging messages were transient, never stored
This commit is contained in:
Joshua Horton 2021-02-22 16:40:11 +07:00 committed by GitHub
commit 962cf96bbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 21 deletions

View file

@ -8,4 +8,27 @@
import XCGLogger
public let log = XCGLogger(identifier: "KeymanEngine", includeDefaultDestinations: true)
// From XCGLogger docs:
// Note: This creates the log object lazily, which means it's not created until it's actually needed.
public let log: XCGLogger = {
// Default: the 'console', which is read by Xcode but doesn't reach the system logs.
let mainLog = XCGLogger(identifier: "KeymanEngine", includeDefaultDestinations: false)
// Ensures our log messages go out to the device's system log as well as the console.
let systemLogDest = AppleSystemLogDestination(identifier: "")
systemLogDest.showLogIdentifier = true
mainLog.add(destination: systemLogDest)
// Temporary logging level to ensure that app details are reported properly.
mainLog.outputLevel = .info
mainLog.logAppDetails()
#if DEBUG
mainLog.outputLevel = .debug
#else
mainLog.outputLevel = .warning
#endif
return mainLog
}()

View file

@ -15,8 +15,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
KeymanEngine.log.outputLevel = .debug
KeymanEngine.log.logAppDetails()
Manager.applicationGroupIdentifier = "group.KMEI"
Manager.shared.canRemoveDefaultKeyboard = true

View file

@ -10,8 +10,7 @@ import KeymanEngine
class KeyboardViewController: InputViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
KeymanEngine.log.outputLevel = .debug
KeymanEngine.log.logAppDetails()
_ = log // forces init of the log, which is useful in sys-kbd contexts.
Manager.applicationGroupIdentifier = "group.KMEI"
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

View file

@ -54,20 +54,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
SentryManager.start()
// Forces the logs to initialize, as their definitions result in lazy init.
// These references have been configured to also log app details.
_ = log
_ = KeymanEngine.log
UniversalLinks.externalLinkLauncher = { url in
UIApplication.shared.openURL(url)
}
#if DEBUG
KeymanEngine.log.outputLevel = .debug
log.outputLevel = .debug
KeymanEngine.log.logAppDetails()
#else
KeymanEngine.log.outputLevel = .warning
log.outputLevel = .warning
#endif
Manager.applicationGroupIdentifier = "group.KM4I"
// TODO: Assign a subclassed version of InputViewController that implements the image stuff.

View file

@ -8,4 +8,27 @@
import XCGLogger
let log = XCGLogger(identifier: "Keyman", includeDefaultDestinations: true)
// From XCGLogger docs:
// Note: This creates the log object lazily, which means it's not created until it's actually needed.
public let log: XCGLogger = {
// Default: the 'console', which is read by Xcode but doesn't reach the system logs.
let mainLog = XCGLogger(identifier: "Keyman", includeDefaultDestinations: false)
// Ensures our log messages go out to the device's system log as well as the console.
let systemLogDest = AppleSystemLogDestination(identifier: "")
systemLogDest.showLogIdentifier = true
mainLog.add(destination: systemLogDest)
// Temporary logging level to ensure that app details are reported properly.
mainLog.outputLevel = .info
mainLog.logAppDetails()
#if DEBUG
mainLog.outputLevel = .debug
#else
mainLog.outputLevel = .warning
#endif
return mainLog
}()

View file

@ -21,13 +21,9 @@ class KeyboardViewController: InputViewController {
// is enabled. They seem to get blocked otherwise, except in the Simulator.
SentryManager.start(sendingEnabled: true)
}
_ = log
_ = KeymanEngine.log
#if DEBUG
KeymanEngine.log.outputLevel = .debug
KeymanEngine.log.logAppDetails()
#else
KeymanEngine.log.outputLevel = .warning
#endif
Manager.applicationGroupIdentifier = "group.KM4I"
let bundle = Bundle(for: KeyboardViewController.self)