From 331d6958b442dc8f6b043b585e971b21b1729d2d Mon Sep 17 00:00:00 2001 From: jahorton Date: Mon, 22 Feb 2021 11:55:24 +0700 Subject: [PATCH 1/4] fix(ios): log messages were Xcode-only --- ios/engine/KMEI/KeymanEngine/Classes/Log.swift | 17 ++++++++++++++++- ios/keyman/Keyman/Keyman/Log.swift | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Log.swift b/ios/engine/KMEI/KeymanEngine/Classes/Log.swift index 92cf9e28f2..d6683f4d62 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Log.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Log.swift @@ -8,4 +8,19 @@ import XCGLogger -public let log = XCGLogger(identifier: "KeymanEngine", includeDefaultDestinations: true) +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: true) + + // Ensures our log messages go out to the device's system log. + let systemLogDest = AppleSystemLogDestination(identifier: "") + systemLogDest.showLogIdentifier = true +#if DEBUG + systemLogDest.outputLevel = .debug +#else + systemLogDest.outputLevel = .warning +#endif + mainLog.add(destination: systemLogDest) + + return mainLog +}() diff --git a/ios/keyman/Keyman/Keyman/Log.swift b/ios/keyman/Keyman/Keyman/Log.swift index 1ba2871845..38a511865d 100644 --- a/ios/keyman/Keyman/Keyman/Log.swift +++ b/ios/keyman/Keyman/Keyman/Log.swift @@ -8,4 +8,19 @@ import XCGLogger -let log = XCGLogger(identifier: "Keyman", includeDefaultDestinations: true) +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: true) + + // Ensures our log messages go out to the device's system log. + let systemLogDest = AppleSystemLogDestination(identifier: "") + systemLogDest.showLogIdentifier = true +#if DEBUG + systemLogDest.outputLevel = .debug +#else + systemLogDest.outputLevel = .warning +#endif + mainLog.add(destination: systemLogDest) + + return mainLog +}() From aa724804699661187e8d2be4b533a5eeebe346e5 Mon Sep 17 00:00:00 2001 From: jahorton Date: Mon, 22 Feb 2021 13:29:28 +0700 Subject: [PATCH 2/4] change(ios): more log centralization --- .../KMEI/KeymanEngine/Classes/Log.swift | 22 +++++++++++++------ .../KMEI/KeymanEngineDemo/AppDelegate.swift | 2 -- .../KeyboardViewController.swift | 2 -- ios/keyman/Keyman/Keyman/AppDelegate.swift | 13 ++++------- ios/keyman/Keyman/Keyman/Log.swift | 22 +++++++++++++------ .../SWKeyboard/KeyboardViewController.swift | 6 ----- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Log.swift b/ios/engine/KMEI/KeymanEngine/Classes/Log.swift index d6683f4d62..7f8e47e413 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Log.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Log.swift @@ -8,19 +8,27 @@ import XCGLogger +// 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: true) + let mainLog = XCGLogger(identifier: "KeymanEngine", includeDefaultDestinations: false) - // Ensures our log messages go out to the device's system log. + // Ensures our log messages go out to the device's system log as well as the console. let systemLogDest = AppleSystemLogDestination(identifier: "") systemLogDest.showLogIdentifier = true -#if DEBUG - systemLogDest.outputLevel = .debug -#else - systemLogDest.outputLevel = .warning -#endif + 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..9152cead27 100644 --- a/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift +++ b/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift @@ -10,8 +10,6 @@ import KeymanEngine class KeyboardViewController: InputViewController { override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { - KeymanEngine.log.outputLevel = .debug - KeymanEngine.log.logAppDetails() 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 38a511865d..c074921570 100644 --- a/ios/keyman/Keyman/Keyman/Log.swift +++ b/ios/keyman/Keyman/Keyman/Log.swift @@ -8,19 +8,27 @@ import XCGLogger +// 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: true) + let mainLog = XCGLogger(identifier: "Keyman", includeDefaultDestinations: false) - // Ensures our log messages go out to the device's system log. + // Ensures our log messages go out to the device's system log as well as the console. let systemLogDest = AppleSystemLogDestination(identifier: "") systemLogDest.showLogIdentifier = true -#if DEBUG - systemLogDest.outputLevel = .debug -#else - systemLogDest.outputLevel = .warning -#endif + 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..88e1cba3f8 100644 --- a/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift +++ b/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift @@ -22,12 +22,6 @@ class KeyboardViewController: InputViewController { SentryManager.start(sendingEnabled: true) } - #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) From 57f37c8c45b9be9fc15e845d97d6c67c29244393 Mon Sep 17 00:00:00 2001 From: jahorton Date: Mon, 22 Feb 2021 13:31:38 +0700 Subject: [PATCH 3/4] fix(ios): restores a log reference --- ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift b/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift index 88e1cba3f8..0c5a2dcdb3 100644 --- a/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift +++ b/ios/keyman/Keyman/SWKeyboard/KeyboardViewController.swift @@ -21,6 +21,8 @@ class KeyboardViewController: InputViewController { // is enabled. They seem to get blocked otherwise, except in the Simulator. SentryManager.start(sendingEnabled: true) } + _ = log + _ = KeymanEngine.log Manager.applicationGroupIdentifier = "group.KM4I" From 66949ed89d564be376ff3b7e31fd64c15a3f22bd Mon Sep 17 00:00:00 2001 From: jahorton Date: Mon, 22 Feb 2021 13:32:47 +0700 Subject: [PATCH 4/4] fix(ios): one more sys-kbd log ref --- ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift b/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift index 9152cead27..8cf3c85e5a 100644 --- a/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift +++ b/ios/engine/KMEI/SystemKeyboard/KeyboardViewController.swift @@ -10,6 +10,7 @@ import KeymanEngine class KeyboardViewController: InputViewController { override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { + _ = log // forces init of the log, which is useful in sys-kbd contexts. Manager.applicationGroupIdentifier = "group.KMEI" super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) }