From 60a75635e92f9ff33935b1556bfa7cf83ed8036b Mon Sep 17 00:00:00 2001 From: Federico Cappelli Date: Fri, 9 Aug 2024 17:23:19 +0100 Subject: [PATCH 1/7] Logger adoption in subscription and content blocking logging --- .swiftlint.yml | 7 -- DuckDuckGo.xcodeproj/project.pbxproj | 2 + .../xcshareddata/swiftpm/Package.resolved | 9 -- .../xcschemes/sandbox-test-tool.xcscheme | 2 +- DuckDuckGo/Common/Logging/Logging.swift | 4 +- .../ContentBlocker/ContentBlocking.swift | 3 +- DuckDuckGo/Menus/MainMenu.swift | 82 +------------------ .../MacTransparentProxyProvider.swift | 2 +- .../NetworkExtensionTargets/VPNLogger.swift | 3 +- DuckDuckGo/Tab/Model/Tab.swift | 3 +- .../ContentBlockingTabExtension.swift | 5 +- .../SubscriptionErrorReporter.swift | 3 +- ...scriptionPagesUseSubscriptionFeature.swift | 11 +-- DuckDuckGoNotifications/Logging.swift | 2 +- .../Sources/LoginItems/LoginItem.swift | 2 +- .../LoginItemLaunchInformation.swift | 1 - .../FlowManagers/TCPFlowManager.swift | 2 +- .../FlowManagers/UDPFlowManager.swift | 2 +- .../TransparentProxyAppMessageHandler.swift | 2 +- .../TransparentProxyController.swift | 2 +- .../TransparentProxyProvider.swift | 2 +- .../Sources/UDSHelper/UDSClient.swift | 1 - .../Sources/UDSHelper/UDSReceiver.swift | 1 - .../Sources/UDSHelper/UDSServer.swift | 1 - 24 files changed, 28 insertions(+), 126 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 459bfc874e..e96a0f5ab9 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -33,13 +33,6 @@ custom_rules: - keyword message: "Classes should be `final` by default, use explicit `internal` or `public` for non-final classes." severity: error - enforce_os_log_wrapper: - included: ".*\\.swift" - name: "Use `import Common` for os_log instead of `import os.log`" - regex: "^(import (?:os\\.log|os|OSLog))$" - capture_group: 0 - message: "os_log wrapper ensures log args are @autoclosures (computed when needed) and to be able to use String Interpolation." - severity: error # Rule Config cyclomatic_complexity: diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 69668943f2..28caf9a924 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -4286,6 +4286,7 @@ EEF53E172950CED5002D78F4 /* JSAlertViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSAlertViewModelTests.swift; sourceTree = ""; }; F118EA7C2BEA2B8700F77634 /* DefaultSubscriptionFeatureAvailability+DefaultInitializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DefaultSubscriptionFeatureAvailability+DefaultInitializer.swift"; sourceTree = ""; }; F118EA842BEACC7000F77634 /* NonStandardPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonStandardPixel.swift; sourceTree = ""; }; + F132D6AB2C666A8300D85426 /* BrowserServicesKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = BrowserServicesKit; path = ../BrowserServicesKit; sourceTree = ""; }; F1476FBF2C1359FB00EAE46A /* SubscriptionUIHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionUIHandler.swift; sourceTree = ""; }; F188267B2BBEB3AA00D9AC4F /* GeneralPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPixel.swift; sourceTree = ""; }; F188267F2BBEB58100D9AC4F /* PrivacyProPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyProPixel.swift; sourceTree = ""; }; @@ -6810,6 +6811,7 @@ AA585D75248FD31100E9A3E2 = { isa = PBXGroup; children = ( + F132D6AB2C666A8300D85426 /* BrowserServicesKit */, 378B5886295CF2A4002C0CC0 /* Configuration */, 378E279C2970217400FCADA2 /* LocalPackages */, 7BB108552A43375D000AB95F /* LocalThirdParty */, diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 6f15f5f93c..cbc78f183e 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -27,15 +27,6 @@ "version" : "3.0.0" } }, - { - "identity" : "browserserviceskit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/duckduckgo/BrowserServicesKit", - "state" : { - "revision" : "ff87c19636bce8baa34b7984defa779c083f9ce9", - "version" : "181.1.0" - } - }, { "identity" : "content-scope-scripts", "kind" : "remoteSourceControl", diff --git a/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/sandbox-test-tool.xcscheme b/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/sandbox-test-tool.xcscheme index eb7e5e26bb..41730d7069 100644 --- a/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/sandbox-test-tool.xcscheme +++ b/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/sandbox-test-tool.xcscheme @@ -1,7 +1,7 @@ + version = "1.7"> NSMenu { let menu = NSMenu(title: "") - menu.addItem(NSMenuItem(title: "Enable All", action: #selector(enableAllLogsMenuItemAction), target: self)) - menu.addItem(NSMenuItem(title: "Disable All", action: #selector(disableAllLogsMenuItemAction), target: self)) - menu.addItem(.separator()) - - for category in OSLog.AllCategories.allCases.sorted() { - let menuItem = NSMenuItem(title: category, action: #selector(loggingMenuItemAction), target: self) - menuItem.identifier = .init(category) - menu.addItem(menuItem) - } - - menu.addItem(autofillDebugScriptMenuItem - .targetting(self)) - - menu.addItem(.separator()) - let debugLoggingMenuItem = NSMenuItem(title: OSLog.isRunningInDebugEnvironment ? "Disable DEBUG level logging…" : "Enable DEBUG level logging…", action: #selector(debugLoggingMenuItemAction), target: self) - menu.addItem(debugLoggingMenuItem) - if #available(macOS 12.0, *) { let exportLogsMenuItem = NSMenuItem(title: "Save Logs…", action: #selector(exportLogs), target: self) menu.addItem(exportLogsMenuItem) @@ -695,17 +677,6 @@ final class MainMenu: NSMenu { internalUserItem.title = NSApp.delegateTyped.internalUserDecider.isInternalUser ? "Remove Internal User State" : "Set Internal User State" } - private func updateLoggingMenuItems() { - guard let loggingMenu else { return } - - let enabledCategories = OSLog.loggingCategories - for item in loggingMenu.items { - guard let category = item.identifier.map(\.rawValue) else { continue } - - item.state = enabledCategories.contains(category) ? .on : .off - } - } - private func updateAutofillDebugScriptMenuItem() { autofillDebugScriptMenuItem.state = AutofillPreferences().debugScriptEnabled ? .on : .off } @@ -722,63 +693,12 @@ final class MainMenu: NSMenu { customConfigurationUrlMenuItem.title = "Configuration URL: \(AppConfigurationURLProvider().url(for: .privacyConfiguration).absoluteString)" } - @objc private func loggingMenuItemAction(_ sender: NSMenuItem) { - guard let category = sender.identifier?.rawValue else { return } - - if case .on = sender.state { - OSLog.loggingCategories.remove(category) - } else { - OSLog.loggingCategories.insert(category) - } - } - - @objc private func enableAllLogsMenuItemAction(_ sender: NSMenuItem) { - OSLog.loggingCategories = Set(OSLog.AllCategories.allCases) - } - - @objc private func disableAllLogsMenuItemAction(_ sender: NSMenuItem) { - OSLog.loggingCategories = [] - } - @objc private func toggleAutofillScriptDebugSettingsAction(_ sender: NSMenuItem) { AutofillPreferences().debugScriptEnabled = !AutofillPreferences().debugScriptEnabled NotificationCenter.default.post(name: .autofillScriptDebugSettingsDidChange, object: nil) updateAutofillDebugScriptMenuItem() } - @objc private func debugLoggingMenuItemAction(_ sender: NSMenuItem) { -#if APPSTORE - if !OSLog.isRunningInDebugEnvironment { - let alert = NSAlert() - alert.messageText = "Restart with DEBUG logging Enabled not supported for AppStore build" - alert.informativeText = """ - Open terminal and run: - export \(ProcessInfo.Constants.osActivityMode)=\(ProcessInfo.Constants.debug) - "\(Bundle.main.executablePath!)" - """ - alert.runModal() - - return - } -#endif - - let alert = NSAlert() - alert.messageText = "Restart with DEBUG logging \(OSLog.isRunningInDebugEnvironment ? "Disabled" : "Enabled")?" - alert.addButton(withTitle: "Restart").tag = NSApplication.ModalResponse.OK.rawValue - alert.addButton(withTitle: "Cancel").tag = NSApplication.ModalResponse.cancel.rawValue - guard case .OK = alert.runModal() else { return } - - let config = NSWorkspace.OpenConfiguration() - config.createsNewApplicationInstance = true - config.environment = [ProcessInfo.Constants.osActivityMode: (OSLog.isRunningInDebugEnvironment ? "" : ProcessInfo.Constants.debug)] - - NSWorkspace.shared.openApplication(at: Bundle.main.bundleURL, configuration: config) - - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { - NSApp.terminate(nil) - } - } - @available(macOS 12.0, *) @objc private func exportLogs(_ sender: NSMenuItem) { let displayName = Bundle.main.displayName!.replacingOccurrences(of: " ", with: "") diff --git a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacTransparentProxyProvider.swift b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacTransparentProxyProvider.swift index 1c4993210e..2319175e98 100644 --- a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacTransparentProxyProvider.swift +++ b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacTransparentProxyProvider.swift @@ -22,7 +22,7 @@ import Foundation import Networking import NetworkExtension import NetworkProtectionProxy -import os.log // swiftlint:disable:this enforce_os_log_wrapper +import os.log import PixelKit final class MacTransparentProxyProvider: TransparentProxyProvider { diff --git a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/VPNLogger.swift b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/VPNLogger.swift index f230701509..52f8000ea3 100644 --- a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/VPNLogger.swift +++ b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/VPNLogger.swift @@ -18,8 +18,7 @@ import Foundation import NetworkProtection -// swiftlint:disable:next enforce_os_log_wrapper -import OSLog +import os.log /// Logger for the VPN /// diff --git a/DuckDuckGo/Tab/Model/Tab.swift b/DuckDuckGo/Tab/Model/Tab.swift index 66e1d4d423..d1b8f7aeaa 100644 --- a/DuckDuckGo/Tab/Model/Tab.swift +++ b/DuckDuckGo/Tab/Model/Tab.swift @@ -25,6 +25,7 @@ import UserScript import WebKit import History import PixelKit +import os.log protocol TabDelegate: ContentOverlayUserScriptDelegate { func tabWillStartNavigation(_ tab: Tab, isUserInitiated: Bool) @@ -1012,7 +1013,7 @@ extension Tab: UserContentControllerDelegate { @MainActor func userContentController(_ userContentController: UserContentController, didInstallContentRuleLists contentRuleLists: [String: WKContentRuleList], userScripts: UserScriptsProvider, updateEvent: ContentBlockerRulesManager.UpdateEvent) { - os_log("didInstallContentRuleLists", log: .contentBlocking, type: .info) + Logger.contentBlocking.info("didInstallContentRuleLists") guard let userScripts = userScripts as? UserScripts else { fatalError("Unexpected UserScripts") } userScripts.debugScript.instrumentation = instrumentation diff --git a/DuckDuckGo/Tab/TabExtensions/ContentBlockingTabExtension.swift b/DuckDuckGo/Tab/TabExtensions/ContentBlockingTabExtension.swift index 7ab4f5ddc6..10b1a31840 100644 --- a/DuckDuckGo/Tab/TabExtensions/ContentBlockingTabExtension.swift +++ b/DuckDuckGo/Tab/TabExtensions/ContentBlockingTabExtension.swift @@ -22,6 +22,7 @@ import Common import ContentBlocking import Foundation import Navigation +import os.log struct DetectedTracker { enum TrackerType { @@ -109,7 +110,7 @@ extension ContentBlockingTabExtension: NavigationResponder { // Ensure Content Blocking Assets (WKContentRuleList&UserScripts) are installed if userContentController?.contentBlockingAssetsInstalled == false && privacyConfigurationManager.privacyConfig.isEnabled(featureKey: .contentBlocking) { - os_log("%d: tabWillWaitForRulesCompilation", log: .contentBlocking, identifier) + Logger.contentBlocking.log("\(self.identifier) tabWillWaitForRulesCompilation") cbaTimeReporter?.tabWillWaitForRulesCompilation(identifier) disableLongDecisionMakingChecks() @@ -118,7 +119,7 @@ extension ContentBlockingTabExtension: NavigationResponder { } await userContentController?.awaitContentBlockingAssetsInstalled() - os_log("%d: Rules Compilation done", log: .contentBlocking, identifier) + Logger.contentBlocking.log("\(self.identifier) Rules Compilation done") cbaTimeReporter?.reportWaitTimeForTabFinishedWaitingForRules(identifier) } else { cbaTimeReporter?.reportNavigationDidNotWaitForRules() diff --git a/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionErrorReporter.swift b/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionErrorReporter.swift index 0058cebd4f..c1d62a8033 100644 --- a/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionErrorReporter.swift +++ b/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionErrorReporter.swift @@ -19,6 +19,7 @@ import Foundation import Common import PixelKit +import os.log enum SubscriptionError: Error { case purchaseFailed, @@ -45,7 +46,7 @@ struct DefaultSubscriptionErrorReporter: SubscriptionErrorReporter { func report(subscriptionActivationError: SubscriptionError) { - os_log(.error, log: .subscription, "Subscription purchase error: %{public}s", subscriptionActivationError.localizedDescription) + Logger.subscription.error("Subscription purchase error: \(subscriptionActivationError.localizedDescription, privacy: .public)") var isStoreError = false var isBackendError = false diff --git a/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUseSubscriptionFeature.swift b/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUseSubscriptionFeature.swift index 2251e93e27..535083717b 100644 --- a/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUseSubscriptionFeature.swift +++ b/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUseSubscriptionFeature.swift @@ -24,6 +24,7 @@ import WebKit import UserScript import Subscription import PixelKit +import os.log /// Use Subscription sub-feature final class SubscriptionPagesUseSubscriptionFeature: Subfeature { @@ -186,14 +187,14 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature { return nil } - os_log(.info, log: .subscription, "[Purchase] Starting purchase for: %{public}s", subscriptionSelection.id) + Logger.subscription.info("[Purchase] Starting purchase for: \(subscriptionSelection.id, privacy: .public)") await uiHandler.presentProgressViewController(withTitle: UserText.purchasingSubscriptionTitle) // Check for active subscriptions if await subscriptionManager.storePurchaseManager().hasActiveSubscription() { PixelKit.fire(PrivacyProPixel.privacyProRestoreAfterPurchaseAttempt) - os_log(.info, log: .subscription, "[Purchase] Found active subscription during purchase") + Logger.subscription.info("[Purchase] Found active subscription during purchase") subscriptionErrorReporter.report(subscriptionActivationError: .hasActiveSubscription) await showSubscriptionFoundAlert(originalMessage: message) await pushPurchaseUpdate(originalMessage: message, purchaseUpdate: PurchaseUpdate(type: "canceled")) @@ -212,7 +213,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature { appStoreRestoreFlow: appStoreRestoreFlow, authEndpointService: subscriptionManager.authEndpointService) - os_log(.info, log: .subscription, "[Purchase] Purchasing") + Logger.subscription.info("[Purchase] Purchasing") switch await appStorePurchaseFlow.purchaseSubscription(with: subscriptionSelection.id, emailAccessToken: emailAccessToken) { case .success(let transactionJWS): purchaseTransactionJWS = transactionJWS @@ -247,11 +248,11 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature { await uiHandler.updateProgressViewController(title: UserText.completingPurchaseTitle) - os_log(.info, log: .subscription, "[Purchase] Completing purchase") + Logger.subscription.info("[Purchase] Completing purchase") let completePurchaseResult = await appStorePurchaseFlow.completeSubscriptionPurchase(with: purchaseTransactionJWS) switch completePurchaseResult { case .success(let purchaseUpdate): - os_log(.info, log: .subscription, "[Purchase] Purchase complete") + Logger.subscription.info("[Purchase] Purchase complete") PixelKit.fire(PrivacyProPixel.privacyProPurchaseSuccess, frequency: .dailyAndCount) PixelKit.fire(PrivacyProPixel.privacyProSubscriptionActivated, frequency: .unique) subscriptionSuccessPixelHandler.fireSuccessfulSubscriptionAttributionPixel() diff --git a/DuckDuckGoNotifications/Logging.swift b/DuckDuckGoNotifications/Logging.swift index 1d8516705b..30c5d6fbe5 100644 --- a/DuckDuckGoNotifications/Logging.swift +++ b/DuckDuckGoNotifications/Logging.swift @@ -17,7 +17,7 @@ // import Foundation -import os // swiftlint:disable:this enforce_os_log_wrapper +import os.log extension OSLog { diff --git a/LocalPackages/LoginItems/Sources/LoginItems/LoginItem.swift b/LocalPackages/LoginItems/Sources/LoginItems/LoginItem.swift index 48a16a8689..eecea5a8ba 100644 --- a/LocalPackages/LoginItems/Sources/LoginItems/LoginItem.swift +++ b/LocalPackages/LoginItems/Sources/LoginItems/LoginItem.swift @@ -17,7 +17,7 @@ // import AppKit -import os.log // swiftlint:disable:this enforce_os_log_wrapper +import os.log import Foundation import ServiceManagement diff --git a/LocalPackages/LoginItems/Sources/LoginItems/LoginItemLaunchInformation.swift b/LocalPackages/LoginItems/Sources/LoginItems/LoginItemLaunchInformation.swift index f6e559f430..802388b5c4 100644 --- a/LocalPackages/LoginItems/Sources/LoginItems/LoginItemLaunchInformation.swift +++ b/LocalPackages/LoginItems/Sources/LoginItems/LoginItemLaunchInformation.swift @@ -18,7 +18,6 @@ import Foundation import AppKit -// swiftlint:disable:next enforce_os_log_wrapper import os.log public struct LoginItemLaunchInformation: Equatable, Hashable { diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/TCPFlowManager.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/TCPFlowManager.swift index edf987d201..dcfb727d6b 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/TCPFlowManager.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/TCPFlowManager.swift @@ -18,7 +18,7 @@ import Foundation import NetworkExtension -import OSLog // swiftlint:disable:this enforce_os_log_wrapper +import os.log /// A private global actor to handle UDP flows management /// diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/UDPFlowManager.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/UDPFlowManager.swift index 000f37d20e..58fbc4dd1e 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/UDPFlowManager.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/FlowManagers/UDPFlowManager.swift @@ -18,7 +18,7 @@ import Foundation import NetworkExtension -import OSLog // swiftlint:disable:this enforce_os_log_wrapper +import os.log /// A private global actor to handle UDP flows management /// diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/IPC/TransparentProxyAppMessageHandler.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/IPC/TransparentProxyAppMessageHandler.swift index 988ffd1f77..48ae78e457 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/IPC/TransparentProxyAppMessageHandler.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/IPC/TransparentProxyAppMessageHandler.swift @@ -17,7 +17,7 @@ // import Foundation -import OSLog // swiftlint:disable:this enforce_os_log_wrapper +import os.log import NetworkExtension /// Handles app messages diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyController.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyController.swift index fdc7fb3177..c936936427 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyController.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyController.swift @@ -20,7 +20,7 @@ import Combine import Foundation import NetworkExtension import NetworkProtection -import OSLog // swiftlint:disable:this enforce_os_log_wrapper +import os.log import PixelKit import SystemExtensions diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyProvider.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyProvider.swift index c71dbc9ee1..ae57c6416f 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyProvider.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionProxy/TransparentProxyProvider.swift @@ -20,7 +20,7 @@ import Combine import Foundation import NetworkExtension import NetworkProtection -import os.log // swiftlint:disable:this enforce_os_log_wrapper +import os.log import SystemConfiguration open class TransparentProxyProvider: NETransparentProxyProvider { diff --git a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift index 023f350761..1c3f153176 100644 --- a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift +++ b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift @@ -18,7 +18,6 @@ import Foundation import Network -// swiftlint:disable:next enforce_os_log_wrapper import os.log public actor UDSClient { diff --git a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSReceiver.swift b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSReceiver.swift index 90e55c25dd..6ad9e5bef6 100644 --- a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSReceiver.swift +++ b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSReceiver.swift @@ -18,7 +18,6 @@ import Foundation import Network -// swiftlint:disable:next enforce_os_log_wrapper import os.log typealias UDSMessageLength = UInt16 diff --git a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift index 41812e5819..ed72e65fb7 100644 --- a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift +++ b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift @@ -18,7 +18,6 @@ import Foundation import Network -// swiftlint:disable:next enforce_os_log_wrapper import os.log /// Convenience Hashable support for `NWConnection`, so we can use `Set` From 6145723f32fdc7a601423ac69aefb1c9dc0b3550 Mon Sep 17 00:00:00 2001 From: Federico Cappelli Date: Tue, 13 Aug 2024 12:56:15 +0100 Subject: [PATCH 2/7] Password manager logs --- .../View/NavigationBarViewController.swift | 10 +++++----- DuckDuckGo/Sync/SyncCredentialsAdapter.swift | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift b/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift index a8eee48ad4..ed07f0746a 100644 --- a/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift +++ b/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift @@ -21,7 +21,7 @@ import Combine import Common import BrowserServicesKit import PixelKit - +import os.log import NetworkProtection import NetworkProtectionIPC import NetworkProtectionUI @@ -866,23 +866,23 @@ final class NavigationBarViewController: NSViewController { let autofillPreferences = AutofillPreferences() if autofillPreferences.askToSaveUsernamesAndPasswords, let credentials = data.credentials { - os_log("Presenting Save Credentials popover", log: .passwordManager) + Logger.passwordManager.debug("Presenting Save Credentials popover") popovers.displaySaveCredentials(credentials, automaticallySaved: data.automaticallySavedCredentials, usingView: passwordManagementButton, withDelegate: self) } else if autofillPreferences.askToSavePaymentMethods, let card = data.creditCard { - os_log("Presenting Save Payment Method popover", log: .passwordManager) + Logger.passwordManager.debug("Presenting Save Payment Method popover") popovers.displaySavePaymentMethod(card, usingView: passwordManagementButton, withDelegate: self) } else if autofillPreferences.askToSaveAddresses, let identity = data.identity { - os_log("Presenting Save Identity popover", log: .passwordManager) + Logger.passwordManager.debug("Presenting Save Identity popover") popovers.displaySaveIdentity(identity, usingView: passwordManagementButton, withDelegate: self) } else { - os_log("Received save autofill data call, but there was no data to present", log: .passwordManager) + Logger.passwordManager.error("Received save autofill data call, but there was no data to present") } } diff --git a/DuckDuckGo/Sync/SyncCredentialsAdapter.swift b/DuckDuckGo/Sync/SyncCredentialsAdapter.swift index 4ffaa44081..aa857a40cb 100644 --- a/DuckDuckGo/Sync/SyncCredentialsAdapter.swift +++ b/DuckDuckGo/Sync/SyncCredentialsAdapter.swift @@ -38,8 +38,7 @@ final class SyncCredentialsAdapter { databaseCleaner = CredentialsDatabaseCleaner( secureVaultFactory: secureVaultFactory, secureVaultErrorReporter: SecureVaultReporter.shared, - errorEvents: CredentialsCleanupErrorHandling(), - log: .passwordManager + errorEvents: CredentialsCleanupErrorHandling() ) } From ef70c246257a81fcde968a2f1eddc359288e951e Mon Sep 17 00:00:00 2001 From: Federico Cappelli Date: Tue, 13 Aug 2024 15:02:46 +0100 Subject: [PATCH 3/7] remote messaging logs --- DuckDuckGo/Configuration/ConfigurationManager.swift | 1 - DuckDuckGo/RemoteMessaging/ActiveRemoteMessageModel.swift | 5 +++-- DuckDuckGo/RemoteMessaging/RemoteMessagingClient.swift | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/DuckDuckGo/Configuration/ConfigurationManager.swift b/DuckDuckGo/Configuration/ConfigurationManager.swift index daa5a503ff..f7bd81720b 100644 --- a/DuckDuckGo/Configuration/ConfigurationManager.swift +++ b/DuckDuckGo/Configuration/ConfigurationManager.swift @@ -68,7 +68,6 @@ final class ConfigurationManager { private var lastRefreshCheckTime: Date = Date() private lazy var fetcher = ConfigurationFetcher(store: ConfigurationStore.shared, - log: .config, eventMapping: Self.configurationDebugEvents) static let configurationDebugEvents = EventMapping { event, error, _, _ in diff --git a/DuckDuckGo/RemoteMessaging/ActiveRemoteMessageModel.swift b/DuckDuckGo/RemoteMessaging/ActiveRemoteMessageModel.swift index 766298e177..854d989b07 100644 --- a/DuckDuckGo/RemoteMessaging/ActiveRemoteMessageModel.swift +++ b/DuckDuckGo/RemoteMessaging/ActiveRemoteMessageModel.swift @@ -22,6 +22,7 @@ import Common import Foundation import PixelKit import RemoteMessaging +import os.log /** * This is used to feed a remote message to the home page view. @@ -137,12 +138,12 @@ final class ActiveRemoteMessageModel: ObservableObject { guard let remoteMessage, let store = store() else { return } - os_log("Remote message shown: %s", log: .remoteMessaging, type: .info, remoteMessage.id) + Logger.remoteMessaging.info("Remote message shown: \(remoteMessage.id, privacy: .public)") if remoteMessage.isMetricsEnabled { PixelKit.fire(GeneralPixel.remoteMessageShown, withAdditionalParameters: ["message": remoteMessage.id]) } if !store.hasShownRemoteMessage(withID: remoteMessage.id) { - os_log("Remote message shown for first time: %s", log: .remoteMessaging, type: .info, remoteMessage.id) + Logger.remoteMessaging.info("Remote message shown for first time: \(remoteMessage.id, privacy: .public)") if remoteMessage.isMetricsEnabled { PixelKit.fire(GeneralPixel.remoteMessageShownUnique, withAdditionalParameters: ["message": remoteMessage.id]) } diff --git a/DuckDuckGo/RemoteMessaging/RemoteMessagingClient.swift b/DuckDuckGo/RemoteMessaging/RemoteMessagingClient.swift index ecc73999fc..72fa9e1271 100644 --- a/DuckDuckGo/RemoteMessaging/RemoteMessagingClient.swift +++ b/DuckDuckGo/RemoteMessaging/RemoteMessagingClient.swift @@ -36,8 +36,7 @@ struct DefaultRemoteMessagingStoreProvider: RemoteMessagingStoreProviding { database: database, notificationCenter: .default, errorEvents: RemoteMessagingStoreErrorHandling(), - remoteMessagingAvailabilityProvider: availabilityProvider, - log: .remoteMessaging + remoteMessagingAvailabilityProvider: availabilityProvider ) } } @@ -98,7 +97,6 @@ final class RemoteMessagingClient: RemoteMessagingProcessing { configurationFetcher: ConfigurationFetcher( store: configurationStore, urlSession: .session(), - log: .remoteMessaging, eventMapping: ConfigurationManager.configurationDebugEvents ), configurationStore: ConfigurationStore.shared From 67c2acb8430b1bdff417d9ed35277e4132238f3b Mon Sep 17 00:00:00 2001 From: Federico Cappelli Date: Tue, 13 Aug 2024 16:05:47 +0100 Subject: [PATCH 4/7] history logs --- DuckDuckGo/History/Services/EncryptedHistoryStore.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo/History/Services/EncryptedHistoryStore.swift b/DuckDuckGo/History/Services/EncryptedHistoryStore.swift index 2b5e9640d4..3c24c8cb55 100644 --- a/DuckDuckGo/History/Services/EncryptedHistoryStore.swift +++ b/DuckDuckGo/History/Services/EncryptedHistoryStore.swift @@ -22,6 +22,7 @@ import CoreData import Combine import History import PixelKit +import os.log final class EncryptedHistoryStore: HistoryStoring { @@ -90,7 +91,7 @@ final class EncryptedHistoryStore: HistoryStoring { for entry in entriesToDelete { context.delete(entry) } - os_log("%d items cleaned from history", log: .history, entriesToDelete.count) + Logger.history.debug("\(entriesToDelete.count) items cleaned from history") } catch { PixelKit.fire(DebugEvent(GeneralPixel.historyRemoveFailed, error: error)) self.context.reset() @@ -114,7 +115,7 @@ final class EncryptedHistoryStore: HistoryStoring { fetchRequest.returnsObjectsAsFaults = false do { let historyEntries = try context.fetch(fetchRequest) - os_log("%d entries loaded from history", log: .history, historyEntries.count) + Logger.history.debug("\(historyEntries.count) entries loaded from history") let history = BrowsingHistory(historyEntries: historyEntries) return .success(history) } catch { From 997539ca03290f5f5b1178aa0c2c6fbc5b23b174 Mon Sep 17 00:00:00 2001 From: Federico Cappelli Date: Tue, 13 Aug 2024 17:36:44 +0100 Subject: [PATCH 5/7] BSK logging categories removed --- DuckDuckGo/Common/Logging/Logging.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DuckDuckGo/Common/Logging/Logging.swift b/DuckDuckGo/Common/Logging/Logging.swift index f249093482..7b3af9d9ea 100644 --- a/DuckDuckGo/Common/Logging/Logging.swift +++ b/DuckDuckGo/Common/Logging/Logging.swift @@ -46,7 +46,7 @@ extension OSLog { enum AllCategories { static var allCases: [String] { - Categories.allCases.map(\.rawValue) + AppCategories.allCases.map(\.rawValue) + AppCategories.allCases.map(\.rawValue) } } From 4f61d313a12bf0b748290ea0bfceacc3a70e82c8 Mon Sep 17 00:00:00 2001 From: Federico Cappelli Date: Mon, 19 Aug 2024 10:25:48 +0100 Subject: [PATCH 6/7] BSK from branch --- DuckDuckGo.xcodeproj/project.pbxproj | 6 ++---- .../xcshareddata/swiftpm/Package.resolved | 11 ++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index a2509a275f..4685c837f7 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -4292,7 +4292,6 @@ EEF53E172950CED5002D78F4 /* JSAlertViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSAlertViewModelTests.swift; sourceTree = ""; }; F118EA7C2BEA2B8700F77634 /* DefaultSubscriptionFeatureAvailability+DefaultInitializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DefaultSubscriptionFeatureAvailability+DefaultInitializer.swift"; sourceTree = ""; }; F118EA842BEACC7000F77634 /* NonStandardPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonStandardPixel.swift; sourceTree = ""; }; - F132D6AB2C666A8300D85426 /* BrowserServicesKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = BrowserServicesKit; path = ../BrowserServicesKit; sourceTree = ""; }; F1476FBF2C1359FB00EAE46A /* SubscriptionUIHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionUIHandler.swift; sourceTree = ""; }; F188267B2BBEB3AA00D9AC4F /* GeneralPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPixel.swift; sourceTree = ""; }; F188267F2BBEB58100D9AC4F /* PrivacyProPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyProPixel.swift; sourceTree = ""; }; @@ -6825,7 +6824,6 @@ AA585D75248FD31100E9A3E2 = { isa = PBXGroup; children = ( - F132D6AB2C666A8300D85426 /* BrowserServicesKit */, 378B5886295CF2A4002C0CC0 /* Configuration */, 378E279C2970217400FCADA2 /* LocalPackages */, 7BB108552A43375D000AB95F /* LocalThirdParty */, @@ -13448,8 +13446,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { - kind = exactVersion; - version = 184.0.1; + branch = fcappelli/oslog_to_logger; + kind = branch; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e71fc310d6..f8855340cd 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -27,6 +27,15 @@ "version" : "3.0.0" } }, + { + "identity" : "browserserviceskit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/duckduckgo/BrowserServicesKit", + "state" : { + "branch" : "fcappelli/oslog_to_logger", + "revision" : "f61b54c293e5a5564694b5ba99873ca5e9ec1a05" + } + }, { "identity" : "content-scope-scripts", "kind" : "remoteSourceControl", @@ -66,7 +75,7 @@ { "identity" : "lottie-spm", "kind" : "remoteSourceControl", - "location" : "https://github.com/airbnb/lottie-spm", + "location" : "https://github.com/airbnb/lottie-spm.git", "state" : { "revision" : "1d29eccc24cc8b75bff9f6804155112c0ffc9605", "version" : "4.4.3" From 084950906e7c4915b47054cba6ae0872d6efacd8 Mon Sep 17 00:00:00 2001 From: Federico Cappelli Date: Tue, 20 Aug 2024 14:10:33 +0100 Subject: [PATCH 7/7] BSK 185.0.0 --- DuckDuckGo.xcodeproj/project.pbxproj | 4 ++-- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- LocalPackages/DataBrokerProtection/Package.swift | 2 +- LocalPackages/NetworkProtectionMac/Package.swift | 2 +- LocalPackages/SubscriptionUI/Package.swift | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index bb509e7220..4e271d21e7 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -13452,8 +13452,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { - branch = fcappelli/oslog_to_logger; - kind = branch; + kind = exactVersion; + version = 185.0.0; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f8855340cd..0a31c48e86 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "branch" : "fcappelli/oslog_to_logger", - "revision" : "f61b54c293e5a5564694b5ba99873ca5e9ec1a05" + "revision" : "2efee14db4d30ac73916794de4d262b745a5f413", + "version" : "185.0.0" } }, { diff --git a/LocalPackages/DataBrokerProtection/Package.swift b/LocalPackages/DataBrokerProtection/Package.swift index 3f55cd980c..9189f243a3 100644 --- a/LocalPackages/DataBrokerProtection/Package.swift +++ b/LocalPackages/DataBrokerProtection/Package.swift @@ -29,7 +29,7 @@ let package = Package( targets: ["DataBrokerProtection"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "184.0.3"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "185.0.0"), .package(path: "../SwiftUIExtensions"), .package(path: "../XPCHelper"), ], diff --git a/LocalPackages/NetworkProtectionMac/Package.swift b/LocalPackages/NetworkProtectionMac/Package.swift index 635a577bbd..01cfa2e187 100644 --- a/LocalPackages/NetworkProtectionMac/Package.swift +++ b/LocalPackages/NetworkProtectionMac/Package.swift @@ -32,7 +32,7 @@ let package = Package( .library(name: "VPNAppLauncher", targets: ["VPNAppLauncher"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "184.0.3"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "185.0.0"), .package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.3"), .package(path: "../AppLauncher"), .package(path: "../UDSHelper"), diff --git a/LocalPackages/SubscriptionUI/Package.swift b/LocalPackages/SubscriptionUI/Package.swift index fd80f36341..9c01fa5733 100644 --- a/LocalPackages/SubscriptionUI/Package.swift +++ b/LocalPackages/SubscriptionUI/Package.swift @@ -12,7 +12,7 @@ let package = Package( targets: ["SubscriptionUI"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "184.0.3"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "185.0.0"), .package(path: "../SwiftUIExtensions") ], targets: [