diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Log.swift b/ios/engine/KMEI/KeymanEngine/Classes/Log.swift index 92cf9e28f2..7f8e47e413 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Log.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Log.swift @@ -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 +}() diff --git a/ios/engine/KMEI/KeymanEngineDemo/AppDelegate.swift b/ios/engine/KMEI/KeymanEngineDemo/AppDelegate.swift index 1e643d76f0..9eb651ca01 100644 --- a/ios/engine/KMEI/KeymanEngineDemo/AppDelegate.swift +++ b/ios/engine/KMEI/KeymanEngineDemo/AppDelegate.swift @@ -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 diff --git a/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift b/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift index 9a54cdcc8e..8cf3c85e5a 100644 --- a/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift +++ b/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift @@ -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) } diff --git a/ios/keyman/Keyman/Keyman/AppDelegate.swift b/ios/keyman/Keyman/Keyman/AppDelegate.swift index c5ce2f46d5..bb09f19918 100644 --- a/ios/keyman/Keyman/Keyman/AppDelegate.swift +++ b/ios/keyman/Keyman/Keyman/AppDelegate.swift @@ -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. diff --git a/ios/keyman/Keyman/Keyman/Log.swift b/ios/keyman/Keyman/Keyman/Log.swift index 1ba2871845..c074921570 100644 --- a/ios/keyman/Keyman/Keyman/Log.swift +++ b/ios/keyman/Keyman/Keyman/Log.swift @@ -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 +}() diff --git a/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift b/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift index 8e716607bb..0c5a2dcdb3 100644 --- a/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift +++ b/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift @@ -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)