Skip to content

Commit 68b64cb

Browse files
author
Kaylee
committed
Use os logging more
1 parent 7fc1522 commit 68b64cb

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

Sources/App/Defaults.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import os
23

34

45
/// Singleton. Wrapper around UserDefaults.standard that provides a nice interface to the app's preferences
@@ -99,7 +100,7 @@ final class Defaults: NSObject {
99100
seenEpisodes.insert(newItem.episode)
100101
uniqueItems.append(newItem)
101102
} else {
102-
NSLog("Discarding duplicate history item: \(newItem)")
103+
os_log("Discarding duplicate history item: %{public}@", log: .main, type: .info, "\(newItem)")
103104
}
104105
}
105106
}
@@ -199,7 +200,7 @@ final class Defaults: NSObject {
199200

200201
// Migrate from single-feed to multi-feed
201202
if let legacyFeedURLString = UserDefaults.standard.string(forKey: "feedURL") {
202-
NSLog("Migrating feed URLs defaults")
203+
os_log("Migrating feed URLs defaults", log: .main, type: .info)
203204
UserDefaults.standard.set(nil, forKey: "feedURL")
204205
if let legacyFeedURL = URL(string: legacyFeedURLString) {
205206
feeds.append(Feed(name: "ShowRSS", url: legacyFeedURL))

Sources/App/FeedChecker.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import AppKit
3+
import os
34

45

56
enum FeedCheckerError: Error {
@@ -83,7 +84,7 @@ final class FeedChecker {
8384

8485
// Skip check if downloads directory isn't currently available
8586
guard Defaults.shared.isTorrentsSavePathValid else {
86-
NSLog("Skipping feed check: downloads directory is not available")
87+
os_log("Skipping feed check: downloads directory is not available", log: .helper, type: .info)
8788
lastCheckStatus = .skipped(Date())
8889
return
8990
}
@@ -94,7 +95,7 @@ final class FeedChecker {
9495
Defaults.shared.hasValidFeeds,
9596
let downloadOptions = Defaults.shared.downloadOptions
9697
else {
97-
NSLog("Skipping feed check: invalid preferences")
98+
os_log("Skipping feed check: invalid preferences", log: .helper, type: .info)
9899
lastCheckStatus = .skipped(Date())
99100
return
100101
}
@@ -112,12 +113,12 @@ final class FeedChecker {
112113
completion: { [weak self] result in
113114
switch result {
114115
case .success(let downloadedEpisodes):
115-
NSLog("Checking feed succeeded, \(downloadedEpisodes.count) new episodes found")
116+
os_log("Checking feed succeeded, %d new episodes found", log: .main, type: .info, downloadedEpisodes.count)
116117
// Deal with new files
117118
self?.handleDownloadedEpisodes(downloadedEpisodes)
118119
self?.lastCheckStatus = .successful(Date())
119120
case .failure(let error):
120-
NSLog("Feed Helper error (checking feed): \(error)")
121+
os_log("Feed Helper error (checking feed): %{public}@", log: .main, type: .error, error.localizedDescription)
121122
self?.lastCheckStatus = .failed(Date(), error)
122123
}
123124
}

Sources/Feed Helper/FeedParser.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import os
23

34

45
private extension XMLNode {
@@ -13,18 +14,18 @@ private extension Episode {
1314
init?(itemNode: XMLNode, feed: Feed) {
1415
// Get the .torrent URL or magnet link
1516
guard let urlString = itemNode["enclosure/@url"] ?? itemNode["link/@href"] ?? itemNode["link"] else {
16-
NSLog("Missing feed item URL")
17+
os_log("Missing feed item URL", log: .helper, type: .info)
1718
return nil
1819
}
1920

2021
guard let url = URL(string: urlString) else {
21-
NSLog("Invalid feed item URL: \(urlString)")
22+
os_log("Invalid feed item URL: %{public}@", log: .helper, type: .info, urlString)
2223
return nil
2324
}
2425

2526
// Get the title (includes show name and season/episode numbers)
2627
guard let title = itemNode["title"], title != "" else {
27-
NSLog("Missing or empty feed item title")
28+
os_log("Missing or empty feed item title", log: .helper, type: .info)
2829
return nil
2930
}
3031

@@ -43,7 +44,7 @@ private extension Episode {
4344
/// Supports additional data specified with the `tv` namespace.
4445
enum FeedParser {
4546
static func parse(feed: Feed, feedContents: Data) throws -> [Episode] {
46-
NSLog("Parsing feed")
47+
os_log("Parsing feed...", log: .helper, type: .info)
4748

4849
// Parse xml
4950
let xml = try XMLDocument(data: feedContents)
@@ -56,7 +57,7 @@ enum FeedParser {
5657
// Extract episodes from NSXMLNodes
5758
let episodes = itemNodes.compactMap { Episode(itemNode: $0, feed: feed) }
5859

59-
NSLog("Parsed \(episodes.count) episodes")
60+
os_log("Parsed %d episodes", log: .helper, type: .info, episodes.count)
6061

6162
return episodes
6263
}

Sources/Shared/SandboxBookmarks.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import os
23

34

45
// In a sandboxed environment, URL bookmarks can be passed from an app to an unpriviledged
@@ -21,7 +22,7 @@ extension URL {
2122
do {
2223
self = try URL(resolvingBookmarkData: sandboxBookmark, bookmarkDataIsStale: &isStale)
2324
} catch {
24-
NSLog("Could not get URL from bookmark: \(error)")
25+
os_log("Could not get URL from bookmark: %{public}@", log: .main, type: .error, error.localizedDescription)
2526
throw error
2627
}
2728
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy