From 76e35cef0a2dc6a16d8584347405e0c04160d942 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 21 Apr 2022 14:44:08 -0700 Subject: [PATCH] use oslog rather than print statements in models package --- .../Sources/Models/CoreData/StorageProvider.swift | 3 +++ .../Sources/Models/DataModels/FeedItem.swift | 12 ++++++------ .../Sources/Models/DataModels/HighlightDep.swift | 4 ++-- .../Sources/Services/DataService/DataService.swift | 5 +++-- .../Services/DataService/Queries/ViewerFetcher.swift | 4 ++-- .../InternalModels/InternalNewsletterEmail.swift | 8 ++++---- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift b/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift index 7a0445e1f..4274d22c9 100644 --- a/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift +++ b/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift @@ -1,5 +1,8 @@ import CoreData import Foundation +import OSLog + +let logger = Logger(subsystem: "app.omnivore", category: "models") /// An `NSPersistentContainer` subclass that lives in the `Models` package so that /// the data model is looked for in the same package bundle (rather than the main bundle) diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift index ac3e82286..198099e35 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift @@ -197,11 +197,11 @@ public extension Sequence where Element == FeedItemDep { do { try context.save() - print("LinkedItems saved succesfully") + logger.debug("LinkedItems saved succesfully") return linkedItems } catch { context.rollback() - print("Failed to save LinkedItems: \(error.localizedDescription)") + logger.debug("Failed to save LinkedItems: \(error.localizedDescription)") return nil } } @@ -239,10 +239,10 @@ public extension LinkedItem { do { try context.save() - print("LinkedItem updated succesfully") + logger.debug("LinkedItem updated succesfully") } catch { context.rollback() - print("Failed to update LinkedItem: \(error.localizedDescription)") + logger.debug("Failed to update LinkedItem: \(error.localizedDescription)") } } @@ -251,10 +251,10 @@ public extension LinkedItem { do { try context.save() - print("LinkedItem removed") + logger.debug("LinkedItem removed") } catch { context.rollback() - print("Failed to remove LinkedItem: \(error.localizedDescription)") + logger.debug("Failed to remove LinkedItem: \(error.localizedDescription)") } } } diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/HighlightDep.swift b/apple/OmnivoreKit/Sources/Models/DataModels/HighlightDep.swift index 25a659703..148d68b08 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/HighlightDep.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/HighlightDep.swift @@ -59,11 +59,11 @@ public struct HighlightDep: Identifiable, Hashable, Codable { do { try context.save() - print("Highlight saved succesfully") + logger.debug("Highlight saved succesfully") return highlight } catch { context.rollback() - print("Failed to save Highlight: \(error.localizedDescription)") + logger.debug("Failed to save Highlight: \(error.localizedDescription)") return nil } } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift index 68776f3fd..5b556ce89 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift @@ -4,13 +4,14 @@ import Foundation import Models import OSLog +let logger = Logger(subsystem: "app.omnivore", category: "data-service") + public final class DataService: ObservableObject { public static var registerIntercomUser: ((String) -> Void)? public static var showIntercomMessenger: (() -> Void)? public let appEnvironment: AppEnvironment let networker: Networker - static let logger = Logger(subsystem: "app.omnivore", category: "data-service") let persistentContainer: PersistentContainer var subscriptions = Set() @@ -48,7 +49,7 @@ public final class DataService: ObservableObject { do { try persistentContainer.viewContext.save() } catch { - DataService.logger.debug("failed to delete objects") + logger.debug("failed to delete objects") } } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift index 2e2e46367..b4bc29196 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift @@ -64,11 +64,11 @@ private struct ViewerInternal { do { try context.save() - DataService.logger.debug("Viewer saved succesfully") + logger.debug("Viewer saved succesfully") return viewer } catch { context.rollback() - DataService.logger.debug("Failed to save Viewer: \(error.localizedDescription)") + logger.debug("Failed to save Viewer: \(error.localizedDescription)") return nil } } diff --git a/apple/OmnivoreKit/Sources/Services/InternalModels/InternalNewsletterEmail.swift b/apple/OmnivoreKit/Sources/Services/InternalModels/InternalNewsletterEmail.swift index 605aaa6db..26c974712 100644 --- a/apple/OmnivoreKit/Sources/Services/InternalModels/InternalNewsletterEmail.swift +++ b/apple/OmnivoreKit/Sources/Services/InternalModels/InternalNewsletterEmail.swift @@ -12,11 +12,11 @@ struct InternalNewsletterEmail { do { try context.save() - DataService.logger.debug("NewsletterEmail saved succesfully") + logger.debug("NewsletterEmail saved succesfully") return newsletterEmail } catch { context.rollback() - DataService.logger.debug("Failed to save NewsletterEmail: \(error.localizedDescription)") + logger.debug("Failed to save NewsletterEmail: \(error.localizedDescription)") return nil } } @@ -36,11 +36,11 @@ extension Sequence where Element == InternalNewsletterEmail { do { try context.save() - DataService.logger.debug("NewsletterEmail saved succesfully") + logger.debug("NewsletterEmail saved succesfully") return newsletterEmails } catch { context.rollback() - DataService.logger.debug("Failed to save NewsletterEmail: \(error.localizedDescription)") + logger.debug("Failed to save NewsletterEmail: \(error.localizedDescription)") return nil } }