Skip to content

Commit

Permalink
Logging refactoring #1 Subscription and Content Blocking (#3219)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1205842942115003/1206750146033742/f
Tech Design URL:
https://app.asana.com/0/1200194497630846/1206777133329590/f

**Description**:

Step 1 of the Logging refactoring
Subscription
Content Blocking
User Scripts
SecureVault
History
Remote messages
General (removed and create local UserDefaultCache logger)
  • Loading branch information
federicocappelli authored Aug 20, 2024
1 parent 0d15d18 commit 7dc4fec
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 25 deletions.
3 changes: 1 addition & 2 deletions Core/ContentBlocking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public final class ContentBlocking {
contentBlockingManager = ContentBlockerRulesManager(rulesSource: contentBlockerRulesSource,
exceptionsSource: exceptionsSource,
lastCompiledRulesStore: lastCompiledRulesStore,
errorReporting: Self.debugEvents,
log: .contentBlockingLog)
errorReporting: Self.debugEvents)

adClickAttributionRulesProvider = AdClickAttributionRulesProvider(config: adClickAttribution,
compiledRulesSource: contentBlockingManager,
Expand Down
4 changes: 1 addition & 3 deletions Core/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import Foundation
import BrowserServicesKit
import Common


public extension OSLog {

Check warning on line 25 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'OSLog' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 25 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

'OSLog' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 25 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / ATB UI Tests

'OSLog' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 25 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Fingerprinting UI Tests

'OSLog' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

enum AppCategories: String, CaseIterable {
case generalLog = "DDG General"
case contentBlockingLog = "DDG Content Blocking"
case adAttributionLog = "DDG AdAttribution"
case lifecycleLog = "DDG Lifecycle"
case autoconsentLog = "DDG Autoconsent"
Expand All @@ -35,7 +35,6 @@ public extension OSLog {
}

@OSLogWrapper(.generalLog) static var generalLog

Check warning on line 37 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 37 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 37 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / ATB UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 37 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Fingerprinting UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f
@OSLogWrapper(.contentBlockingLog) static var contentBlockingLog
@OSLogWrapper(.adAttributionLog) static var adAttributionLog

Check warning on line 38 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 38 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 38 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / ATB UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 38 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Fingerprinting UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f
@OSLogWrapper(.lifecycleLog) static var lifecycleLog

Check warning on line 39 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 39 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 39 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / ATB UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 39 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Fingerprinting UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f
@OSLogWrapper(.autoconsentLog) static var autoconsentLog

Check warning on line 40 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 40 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 40 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / ATB UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f

Check warning on line 40 in Core/Logging.swift

View workflow job for this annotation

GitHub Actions / Fingerprinting UI Tests

'OSLogWrapper' is deprecated: Use Logger.yourFeature instead, see https://app.asana.com/0/1202500774821704/1208001254061393/f
Expand All @@ -48,7 +47,6 @@ public extension OSLog {
#if DEBUG
static var enabledCategories: Set<AppCategories> = [
.generalLog,
.contentBlockingLog,
.adAttributionLog,
.lifecycleLog,
.configurationLog,
Expand Down
3 changes: 1 addition & 2 deletions Core/SyncCredentialsAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public final class SyncCredentialsAdapter {
databaseCleaner = CredentialsDatabaseCleaner(
secureVaultFactory: secureVaultFactory,
secureVaultErrorReporter: secureVaultErrorReporter,
errorEvents: CredentialsCleanupErrorHandling(),
log: .generalLog
errorEvents: CredentialsCleanupErrorHandling()
)
}

Expand Down
6 changes: 1 addition & 5 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@
F115ED9C2B4EFC8E001A0453 /* TestUtils in Frameworks */ = {isa = PBXBuildFile; productRef = F115ED9B2B4EFC8E001A0453 /* TestUtils */; };
F130D73A1E5776C500C45811 /* OmniBarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F130D7391E5776C500C45811 /* OmniBarDelegate.swift */; };
F132D6A52C62239B00D85426 /* SubscriptionSettingsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F132D6A42C62239B00D85426 /* SubscriptionSettingsHeaderView.swift */; };
F132D6A82C6524B600D85426 /* Logger+Subscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = F132D6A72C6524B600D85426 /* Logger+Subscription.swift */; };
F1386BA41E6846C40062FC3C /* TabDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1386BA31E6846C40062FC3C /* TabDelegate.swift */; };
F13B4BC01F180D8A00814661 /* TabsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13B4BBF1F180D8A00814661 /* TabsModel.swift */; };
F13B4BD31F1822C700814661 /* Tab.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13B4BD21F1822C700814661 /* Tab.swift */; };
Expand Down Expand Up @@ -2777,7 +2776,6 @@
F114C55A1E66EB020018F95F /* NibLoading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibLoading.swift; sourceTree = "<group>"; };
F130D7391E5776C500C45811 /* OmniBarDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OmniBarDelegate.swift; sourceTree = "<group>"; };
F132D6A42C62239B00D85426 /* SubscriptionSettingsHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionSettingsHeaderView.swift; sourceTree = "<group>"; };
F132D6A72C6524B600D85426 /* Logger+Subscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Logger+Subscription.swift"; sourceTree = "<group>"; };
F1386BA31E6846C40062FC3C /* TabDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabDelegate.swift; sourceTree = "<group>"; };
F13B4BBF1F180D8A00814661 /* TabsModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabsModel.swift; sourceTree = "<group>"; };
F13B4BD21F1822C700814661 /* Tab.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tab.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5045,7 +5043,6 @@
isa = PBXGroup;
children = (
F1FDC9342BF51E41006B1435 /* VPNSettings+Environment.swift */,
F132D6A72C6524B600D85426 /* Logger+Subscription.swift */,
D664C7982B289AA000CBFA76 /* WKUserContentController+Handler.swift */,
);
path = Extensions;
Expand Down Expand Up @@ -7325,7 +7322,6 @@
85C861E628FF1B5F00189466 /* HomeViewSectionRenderersExtension.swift in Sources */,
CB825C922C071B1400BCC586 /* AlertView.swift in Sources */,
1DDF40292BA04FCD006850D9 /* SettingsPrivacyProtectionsView.swift in Sources */,
F132D6A82C6524B600D85426 /* Logger+Subscription.swift in Sources */,
6F64AA5F2C49463C00CF4489 /* ShortcutsModel.swift in Sources */,
F1D477C61F2126CC0031ED49 /* OmniBarState.swift in Sources */,
85F2FFCD2211F615006BB258 /* MainViewController+KeyCommands.swift in Sources */,
Expand Down Expand Up @@ -10543,7 +10539,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 184.0.1;
version = 185.0.0;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "b7f595594d9e5d8500a93704d36a5521553bd314",
"version" : "184.0.1"
"revision" : "2efee14db4d30ac73916794de4d262b745a5f413",
"version" : "185.0.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Configuration/ConfigurationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct ConfigurationManager {
}

public static let didUpdateTrackerDependencies = NSNotification.Name(rawValue: "com.duckduckgo.configurationManager.didUpdateTrackerDependencies")
private let fetcher = ConfigurationFetcher(store: ConfigurationStore.shared, log: .configurationLog, eventMapping: Self.configurationDebugEvents)
private let fetcher = ConfigurationFetcher(store: ConfigurationStore.shared, eventMapping: Self.configurationDebugEvents)

private static let configurationDebugEvents = EventMapping<ConfigurationDebugEvents> { event, error, _, _ in
let domainEvent: Pixel.Event
Expand Down
9 changes: 5 additions & 4 deletions DuckDuckGo/HomePageConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import RemoteMessaging
import Common
import Core
import Bookmarks
import os.log

final class HomePageConfiguration: HomePageMessagesConfiguration {

Expand Down Expand Up @@ -79,14 +80,14 @@ final class HomePageConfiguration: HomePageMessagesConfiguration {

private func remoteMessageToShow() -> HomeMessage? {
guard let remoteMessageToPresent = remoteMessagingClient.store.fetchScheduledRemoteMessage() else { return nil }
os_log("Remote message to show: %s", log: .remoteMessaging, type: .info, remoteMessageToPresent.id)
Logger.remoteMessaging.info("Remote message to show: \(remoteMessageToPresent.id)")
return .remoteMessage(remoteMessage: remoteMessageToPresent)
}

func dismissHomeMessage(_ homeMessage: HomeMessage) {
switch homeMessage {
case .remoteMessage(let remoteMessage):
os_log("Home message dismissed: %s", log: .remoteMessaging, type: .info, remoteMessage.id)
Logger.remoteMessaging.info("Home message dismissed: \(remoteMessage.id)")
remoteMessagingClient.store.dismissRemoteMessage(withID: remoteMessage.id)

if let index = homeMessages.firstIndex(of: homeMessage) {
Expand All @@ -100,14 +101,14 @@ final class HomePageConfiguration: HomePageMessagesConfiguration {
func didAppear(_ homeMessage: HomeMessage) {
switch homeMessage {
case .remoteMessage(let remoteMessage):
os_log("Remote message shown: %s", log: .remoteMessaging, type: .info, remoteMessage.id)
Logger.remoteMessaging.info("Remote message shown: \(remoteMessage.id)")
if remoteMessage.isMetricsEnabled {
Pixel.fire(pixel: .remoteMessageShown,
withAdditionalParameters: additionalParameters(for: remoteMessage.id))
}

if !remoteMessagingClient.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)")
if remoteMessage.isMetricsEnabled {
Pixel.fire(pixel: .remoteMessageShownUnique,
withAdditionalParameters: additionalParameters(for: remoteMessage.id))
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Persistence
import RemoteMessaging
import SwiftUI
import BrowserServicesKit
import os.log

class HomeViewController: UIViewController, NewTabPage {

Expand Down Expand Up @@ -183,7 +184,7 @@ class HomeViewController: UIViewController, NewTabPage {

@objc func remoteMessagesDidChange() {
DispatchQueue.main.async {
os_log("Remote messages did change", log: .remoteMessaging, type: .info)
Logger.remoteMessaging.info("Remote messages did change")
self.collectionView.refreshHomeConfiguration()
self.refresh()
}
Expand Down
8 changes: 4 additions & 4 deletions DuckDuckGo/RemoteMessagingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import BrowserServicesKit
import Persistence
import Bookmarks
import RemoteMessaging
import os.log

final class RemoteMessagingClient: RemoteMessagingProcessing {

Expand Down Expand Up @@ -65,15 +66,14 @@ final class RemoteMessagingClient: RemoteMessagingProcessing {
duckPlayerStorage: duckPlayerStorage
)
let configFetcher = RemoteMessagingConfigFetcher(
configurationFetcher: ConfigurationFetcher(store: configurationStore, urlSession: .session(), log: .remoteMessaging, eventMapping: nil),
configurationFetcher: ConfigurationFetcher(store: configurationStore, urlSession: .session(), eventMapping: nil),
configurationStore: configurationStore
)
let remoteMessagingStore = RemoteMessagingStore(
database: database,
notificationCenter: notificationCenter,
errorEvents: errorEvents,
remoteMessagingAvailabilityProvider: remoteMessagingAvailabilityProvider,
log: .remoteMessaging
remoteMessagingAvailabilityProvider: remoteMessagingAvailabilityProvider
)
self.init(
configMatcherProvider: provider,
Expand Down Expand Up @@ -146,7 +146,7 @@ extension RemoteMessagingClient {
do {
try BGTaskScheduler.shared.submit(task)
} catch {
os_log("Failed to schedule background task: %@", log: OSLog.remoteMessaging, type: .error, error.localizedDescription)
Logger.remoteMessaging.error("Failed to schedule background task: \(error.localizedDescription, privacy: .public)")
}
#endif
}
Expand Down

0 comments on commit 7dc4fec

Please sign in to comment.