Get rid of commonglog

This commit is contained in:
Nathan Mattes 2023-09-21 00:20:57 +02:00
parent a46a0ca015
commit 74c324f9cf
28 changed files with 7 additions and 82 deletions

View File

@ -19,15 +19,6 @@
"version": "4.2.0"
}
},
{
"package": "CommonOSLog",
"repositoryURL": "https://github.com/MainasuK/CommonOSLog",
"state": {
"branch": null,
"revision": "c121624a30698e9886efe38aebb36ff51c01b6c2",
"version": "0.1.1"
}
},
{
"package": "FaviconFinder",
"repositoryURL": "https://github.com/will-lumley/FaviconFinder.git",

View File

@ -8,7 +8,6 @@
import UIKit
import Combine
import CoreDataStack
import CommonOSLog
import MastodonCore
final class SearchHistoryViewModel {

View File

@ -10,7 +10,6 @@ import Combine
import CoreData
import CoreDataStack
import GameplayKit
import CommonOSLog
import MastodonSDK
import MastodonCore

View File

@ -46,7 +46,6 @@ let package = Package(
.package(url: "https://github.com/kean/Nuke-FLAnimatedImage-Plugin.git", from: "8.0.0"),
.package(url: "https://github.com/kean/Nuke.git", from: "10.3.1"),
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess.git", from: "4.2.2"),
.package(url: "https://github.com/MainasuK/CommonOSLog", from: "0.1.1"),
.package(url: "https://github.com/MainasuK/FPSIndicator.git", from: "1.0.0"),
.package(url: "https://github.com/slackhq/PanModal.git", from: "1.2.7"),
.package(url: "https://github.com/TimOliver/TOCropViewController.git", from: "2.6.1"),
@ -93,7 +92,6 @@ let package = Package(
"MastodonSDK",
.product(name: "Alamofire", package: "Alamofire"),
.product(name: "AlamofireImage", package: "AlamofireImage"),
.product(name: "CommonOSLog", package: "CommonOSLog"),
.product(name: "ArkanaKeys", package: "ArkanaKeys"),
.product(name: "KeychainAccess", package: "KeychainAccess"),
.product(name: "MetaTextKit", package: "MetaTextKit")

View File

@ -9,7 +9,6 @@ import os.log
import CoreDataStack
import Foundation
import Combine
import CommonOSLog
import MastodonCommon
import MastodonSDK
@ -49,8 +48,6 @@ extension APIService {
)
let flag = result.isNewInsertion ? "+" : "-"
let logger = Logger(subsystem: "APIService", category: "AccountInfo")
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch mastodon user [\(flag)](\(response.value.id))\(response.value.username)")
}
return response

View File

@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {
@ -65,7 +64,6 @@ extension APIService {
user: ManagedObjectRecord<MastodonUser>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
let logger = Logger(subsystem: "APIService", category: "Block")
let managedObjectContext = backgroundManagedObjectContext
let blockContext: MastodonBlockContext = try await managedObjectContext.performChanges {
@ -84,7 +82,7 @@ extension APIService {
// will do block action. set to unfollow
user.update(isFollowing: false, by: me)
}
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user[\(user.id)](\(user.username)) block state: \(!isBlocking)")
return MastodonBlockContext(
sourceUserID: me.id,
targetUserID: user.id,
@ -115,7 +113,6 @@ extension APIService {
}
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(blockContext.targetUserID)](\(blockContext.targetUsername)) block failure: \(error.localizedDescription)")
}
try await managedObjectContext.performChanges {
@ -135,12 +132,10 @@ extension APIService {
networkDate: response.networkDate
)
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(blockContext.targetUserID)](\(blockContext.targetUsername)) block state: \(relationship.blocking)")
case .failure:
// rollback
user.update(isBlocking: blockContext.isBlocking, by: me)
user.update(isFollowing: blockContext.isFollowing, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] rollback user[\(blockContext.targetUserID)](\(blockContext.targetUsername)) block state")
}
}

View File

@ -10,7 +10,6 @@ import Combine
import MastodonSDK
import CoreData
import CoreDataStack
import CommonOSLog
extension APIService {
@ -23,8 +22,7 @@ extension APIService {
record: ManagedObjectRecord<Status>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Status> {
let logger = Logger(subsystem: "APIService", category: "Bookmark")
let managedObjectContext = backgroundManagedObjectContext
// update bookmark state and retrieve bookmark context
@ -42,7 +40,6 @@ extension APIService {
statusID: status.id,
isBookmarked: isBookmarked
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status bookmark: \(!isBookmarked)")
return context
}
@ -59,7 +56,6 @@ extension APIService {
result = .success(response)
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update bookmark failure: \(error.localizedDescription)")
}
// update bookmark state
@ -83,11 +79,9 @@ extension APIService {
networkDate: response.networkDate
)
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status bookmark: \(response.value.bookmarked.debugDescription)")
case .failure:
// rollback
status.update(bookmarked: bookmarkContext.isBookmarked, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): rollback status bookmark")
}
}

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -6,7 +6,6 @@
//
import Combine
import CommonOSLog
import CoreData
import CoreDataStack
import Foundation

View File

@ -11,7 +11,6 @@ import Combine
import MastodonSDK
import CoreData
import CoreDataStack
import CommonOSLog
extension APIService {
@ -25,8 +24,7 @@ extension APIService {
record: ManagedObjectRecord<Status>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Status> {
let logger = Logger(subsystem: "APIService", category: "Favorite")
let managedObjectContext = backgroundManagedObjectContext
// update like state and retrieve like context
@ -48,7 +46,6 @@ extension APIService {
isFavorited: isFavorited,
favoritedCount: favoritedCount
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status favorite: \(!isFavorited), \(favoriteCount)")
return context
}
@ -65,7 +62,6 @@ extension APIService {
result = .success(response)
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update favorite failure: \(error.localizedDescription)")
}
// update like state
@ -92,12 +88,10 @@ extension APIService {
if favoriteContext.isFavorited {
status.update(favouritesCount: max(0, status.favouritesCount - 1)) // undo API return count has delay. Needs -1 local
}
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status favorite: \(response.value.favourited.debugDescription)")
case .failure:
// rollback
status.update(liked: favoriteContext.isFavorited, by: me)
status.update(favouritesCount: favoriteContext.favoritedCount)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): rollback status favorite")
}
}

View File

@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {
@ -34,8 +33,7 @@ extension APIService {
user: ManagedObjectRecord<MastodonUser>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
let logger = Logger(subsystem: "APIService", category: "Follow")
let managedObjectContext = backgroundManagedObjectContext
let _followContext: MastodonFollowContext? = try await managedObjectContext.performChanges {
guard let me = authenticationBox.authenticationRecord.object(in: managedObjectContext)?.user else { return nil }
@ -49,17 +47,14 @@ extension APIService {
// unfollow
user.update(isFollowing: false, by: me)
user.update(isFollowRequested: false, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user friendship: undo follow")
} else {
// follow
if user.locked {
user.update(isFollowing: false, by: me)
user.update(isFollowRequested: true, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user friendship: pending follow")
} else {
user.update(isFollowing: true, by: me)
user.update(isFollowRequested: false, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user friendship: following")
}
}
let context = MastodonFollowContext(
@ -88,7 +83,6 @@ extension APIService {
).singleOutput()
result = .success(response)
} catch {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update friendship failure: \(error.localizedDescription)")
result = .failure(error)
}
@ -109,12 +103,10 @@ extension APIService {
)
)
let following = response.value.following
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user friendship: following \(following)")
case .failure:
// rollback
user.update(isFollowing: followContext.isFollowing, by: me)
user.update(isFollowRequested: followContext.isPending, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] rollback user friendship")
}
}

View File

@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {
@ -64,8 +63,7 @@ extension APIService {
user: ManagedObjectRecord<MastodonUser>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
let logger = Logger(subsystem: "APIService", category: "Mute")
let managedObjectContext = backgroundManagedObjectContext
let muteContext: MastodonMuteContext = try await managedObjectContext.performChanges {
guard let user = user.object(in: managedObjectContext),
@ -79,7 +77,6 @@ extension APIService {
// toggle mute state
user.update(isMuting: !isMuting, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user[\(user.id)](\(user.username)) mute state: \(!isMuting)")
return MastodonMuteContext(
sourceUserID: me.id,
targetUserID: user.id,
@ -111,7 +108,6 @@ extension APIService {
}
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(muteContext.targetUserID)](\(muteContext.targetUsername)) mute failure: \(error.localizedDescription)")
}
try await managedObjectContext.performChanges {
@ -131,11 +127,9 @@ extension APIService {
networkDate: response.networkDate
)
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(muteContext.targetUserID)](\(muteContext.targetUsername)) mute state: \(relationship.muting.debugDescription)")
case .failure:
// rollback
user.update(isMuting: muteContext.isMuting, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] rollback user[\(muteContext.targetUserID)](\(muteContext.targetUsername)) mute state")
}
}

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -10,7 +10,6 @@ import Combine
import MastodonSDK
import CoreData
import CoreDataStack
import CommonOSLog
extension APIService {
@ -24,7 +23,6 @@ extension APIService {
record: ManagedObjectRecord<Status>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Status> {
let logger = Logger(subsystem: "APIService", category: "Reblog")
let managedObjectContext = backgroundManagedObjectContext
// update repost state and retrieve repost context
@ -45,7 +43,6 @@ extension APIService {
isReblogged: isReblogged,
rebloggedCount: rebloggedCount
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status reblog: \(!isReblogged), \(reblogCount)")
return reblogContext
}
guard let reblogContext = _reblogContext else {
@ -65,7 +62,6 @@ extension APIService {
result = .success(response)
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update reblog failure: \(error.localizedDescription)")
}
// update repost state
@ -92,12 +88,10 @@ extension APIService {
if reblogContext.isReblogged {
status.update(reblogsCount: max(0, status.reblogsCount - 1)) // undo API return count has delay. Needs -1 local
}
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status reblog: \(!reblogContext.isReblogged)")
case .failure:
// rollback
status.update(reblogged: reblogContext.isReblogged, by: me)
status.update(reblogsCount: reblogContext.rebloggedCount)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): rollback status reblog")
}
}

View File

@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -8,7 +8,6 @@
import Foundation
import Combine
import MastodonSDK
import CommonOSLog
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {

View File

@ -6,7 +6,6 @@
//
import UserNotifications
import CommonOSLog
import CryptoKit
import AlamofireImage
import MastodonCore
@ -22,13 +21,11 @@ class NotificationService: UNNotificationServiceExtension {
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
let privateKey = AppSecret.default.notificationPrivateKey
let auth = AppSecret.default.notificationAuth
guard let encodedPayload = bestAttemptContent.userInfo["p"] as? String else {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: invalid payload", ((#file as NSString).lastPathComponent), #line, #function)
contentHandler(bestAttemptContent)
return
}
@ -36,13 +33,11 @@ class NotificationService: UNNotificationServiceExtension {
guard let encodedPublicKey = bestAttemptContent.userInfo["k"] as? String,
let publicKey = NotificationService.publicKey(encodedPublicKey: encodedPublicKey) else {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: invalid public key", ((#file as NSString).lastPathComponent), #line, #function)
contentHandler(bestAttemptContent)
return
}
guard let encodedSalt = bestAttemptContent.userInfo["s"] as? String else {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: invalid salt", ((#file as NSString).lastPathComponent), #line, #function)
contentHandler(bestAttemptContent)
return
}
@ -75,10 +70,9 @@ class NotificationService: UNNotificationServiceExtension {
ImageDownloader.default.download(URLRequest(url: url), completion: { [weak self] response in
guard let _ = self else { return }
switch response.result {
case .failure(let error):
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: download image %s fail: %s", ((#file as NSString).lastPathComponent), #line, #function, url.debugDescription, error.localizedDescription)
case .failure(_):
break
case .success(let image):
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: download image %s success", ((#file as NSString).lastPathComponent), #line, #function, url.debugDescription)
try? image.pngData()?.write(to: fileURL)
if let attachment = try? UNNotificationAttachment(identifier: filename, url: fileURL, options: nil) {
bestAttemptContent.attachments = [attachment]