Improvements to logging (#457)

* Use `.info` logging in most places.
* Remove old objc logging support.
* Fix table view controller.
* Make sure timeline item content isn't logged.
* Add tests.
This commit is contained in:
Doug
2023-01-17 09:28:01 +00:00
committed by GitHub
parent 4b56e4af73
commit c8937505d7
57 changed files with 542 additions and 275 deletions
+13 -13
View File
@@ -51,8 +51,8 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
NSELogger.logMemory(with: tag)
MXLog.debug("\(tag) #########################################")
MXLog.debug("\(tag) Payload came: \(request.content.userInfo)")
MXLog.info("\(tag) #########################################")
MXLog.info("\(tag) Payload came: \(request.content.userInfo)")
Task {
try await run(with: credentials,
@@ -64,21 +64,21 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
MXLog.debug("\(tag) serviceExtensionTimeWillExpire")
MXLog.warning("\(tag) serviceExtensionTimeWillExpire")
notify()
}
private func run(with credentials: KeychainCredentials,
roomId: String,
eventId: String) async throws {
MXLog.debug("\(tag) run with roomId: \(roomId), eventId: \(eventId)")
MXLog.info("\(tag) run with roomId: \(roomId), eventId: \(eventId)")
let service = NotificationServiceProxy(basePath: URL.sessionsBaseDirectory.path,
userId: credentials.userID)
guard let itemProxy = try await service.notificationItem(roomId: roomId,
eventId: eventId) else {
MXLog.debug("\(tag) got no notification item")
MXLog.error("\(tag) got no notification item")
// Notification should be discarded
return discard()
@@ -88,7 +88,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
// After this some properties of the notification should be set, like title, subtitle, sound etc.
guard let firstContent = try await itemProxy.process(with: roomId,
mediaProvider: nil) else {
MXLog.debug("\(tag) not even first content")
MXLog.error("\(tag) not even first content")
// Notification should be discarded
return discard()
@@ -98,13 +98,13 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
modifiedContent = firstContent
guard itemProxy.requiresMediaProvider else {
MXLog.debug("\(tag) no media needed")
MXLog.info("\(tag) no media needed")
// We've processed the item and no media operations needed, so no need to go further
return notify()
}
MXLog.debug("\(tag) process with media")
MXLog.info("\(tag) process with media")
// There is some media to load, process it again
if let latestContent = try await itemProxy.process(with: roomId,
@@ -126,7 +126,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
let client = try builder.build()
try client.restoreSession(session: credentials.restorationToken.session)
MXLog.debug("\(tag) creating media provider")
MXLog.info("\(tag) creating media provider")
return MediaProvider(mediaProxy: MediaProxy(client: client),
imageCache: .onlyOnDisk,
@@ -135,10 +135,10 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
}
private func notify() {
MXLog.debug("\(tag) notify")
MXLog.info("\(tag) notify")
guard let modifiedContent else {
MXLog.debug("\(tag) notify: no modified content")
MXLog.info("\(tag) notify: no modified content")
return
}
handler?(modifiedContent)
@@ -147,7 +147,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
}
private func discard() {
MXLog.debug("\(tag) discard")
MXLog.info("\(tag) discard")
handler?(UNMutableNotificationContent())
handler = nil
@@ -160,6 +160,6 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
deinit {
NSELogger.logMemory(with: tag)
MXLog.debug("\(tag) deinit")
MXLog.info("\(tag) deinit")
}
}
+1 -1
View File
@@ -102,6 +102,6 @@ class NSELogger {
}
static func logMemory(with tag: String) {
MXLog.debug("\(tag) Memory: footprint: \(formattedMemoryFootprint) - available: \(formattedMemoryAvailable)")
MXLog.info("\(tag) Memory: footprint: \(formattedMemoryFootprint) - available: \(formattedMemoryAvailable)")
}
}
@@ -32,7 +32,7 @@ extension UNMutableNotificationContent {
options: nil)
attachments.append(attachment)
case .failure(let error):
MXLog.debug("Couldn't add media attachment: \(error)")
MXLog.error("Couldn't add media attachment: \(error)")
}
return self
@@ -81,10 +81,11 @@ extension UNMutableNotificationContent {
// Update notification content before displaying the
// communication notification.
let updatedContent = try updating(from: intent)
// swiftlint:disable:next force_cast
return updatedContent.mutableCopy() as! UNMutableNotificationContent
case .failure(let error):
MXLog.debug("Couldn't add sender icon: \(error)")
MXLog.error("Couldn't add sender icon: \(error)")
return self
}
}