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
@@ -71,7 +71,7 @@ class Analytics {
client.stop()
// monitoringClient.stop()
MXLog.debug("Stopped.")
MXLog.info("Stopped.")
}
/// Starts the analytics client if the user has opted in, otherwise does nothing.
@@ -84,7 +84,7 @@ class Analytics {
// Sanity check in case something went wrong.
guard client.isRunning else { return }
MXLog.debug("Started.")
MXLog.info("Started.")
// Catch and log crashes
// MXLogger.logCrashes(true)
@@ -121,7 +121,7 @@ class Analytics {
client.reset()
// monitoringClient.reset()
MXLog.debug("Reset.")
MXLog.info("Reset.")
ServiceLocator.shared.settings.isIdentifiedForAnalytics = false
// Stop collecting crash logs
@@ -146,7 +146,7 @@ class Analytics {
}
client.identify(id: id)
MXLog.debug("Identified.")
MXLog.info("Identified.")
ServiceLocator.shared.settings.isIdentifiedForAnalytics = true
}
@@ -59,7 +59,7 @@ class AnalyticsService {
let newSettings = AnalyticsSettings.new(currentEvent: settings)
switch await userSession.clientProxy.setAccountData(content: newSettings, type: AnalyticsSettings.eventType) {
case .failure:
MXLog.warning("Failed to update analytics settings.")
MXLog.error("Failed to update analytics settings.")
return .failure(.accountDataFailure)
case .success:
MXLog.debug("Successfully updated analytics settings in account data.")
@@ -88,7 +88,7 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
let client = try authenticationService.restoreWithAccessToken(token: token, deviceId: deviceID)
return await userSession(for: client)
} catch {
MXLog.debug(error)
MXLog.error(error)
return .failure(.failedLoggingIn)
}
}
@@ -58,7 +58,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
}
if identifier == .invalid {
MXLog.verbose("Do not start background task: \(name), as OS declined")
MXLog.info("Do not start background task: \(name), as OS declined")
// call expiration handler immediately
expirationHandler?(self)
return nil
@@ -69,7 +69,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
reuse()
}
MXLog.verbose("Start background task #\(identifier.rawValue) - \(name)")
MXLog.info("Start background task #\(identifier.rawValue) - \(name)")
}
func reuse() {
@@ -92,7 +92,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
private func endTask() {
if identifier != .invalid {
MXLog.verbose("End background task #\(identifier.rawValue) - \(name) after \(readableElapsedTime)")
MXLog.info("End background task #\(identifier.rawValue) - \(name) after \(readableElapsedTime)")
application.endBackgroundTask(identifier)
identifier = .invalid
@@ -36,12 +36,12 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol {
isReusable: Bool,
expirationHandler: (() -> Void)?) -> BackgroundTaskProtocol? {
guard let application else {
MXLog.verbose("Do not start background task: \(name). Application is nil")
MXLog.error("Do not start background task: \(name). Application is nil")
return nil
}
if avoidStartingNewTasks(for: application) {
MXLog.verbose("Do not start background task: \(name), as not enough time exists")
MXLog.info("Do not start background task: \(name), as not enough time exists")
// call expiration handler immediately
expirationHandler?()
return nil
@@ -82,7 +82,7 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol {
let appState = application.applicationState
let remainingTime = readableBackgroundTimeRemaining(application.backgroundTimeRemaining)
MXLog.verbose("Background task \(name) \(created ? "started" : "reused") with app state: \(appState) and estimated background time remaining: \(remainingTime)")
MXLog.info("Background task \(name) \(created ? "started" : "reused") with app state: \(appState) and estimated background time remaining: \(remainingTime)")
return result
}
@@ -53,7 +53,7 @@ class BugReportService: BugReportServiceProtocol {
}
options.onCrashedLastRun = { [weak self] event in
MXLog.debug("Sentry detected application was crashed: \(event)")
MXLog.error("Sentry detected application was crashed: \(event)")
self?.lastCrashEventId = event.eventId.sentryIdString
}
}
@@ -79,11 +79,7 @@ class BugReportService: BugReportServiceProtocol {
includeCrashLog: Bool,
githubLabels: [String],
files: [URL]) async throws -> SubmitBugReportResponse {
MXLog.debug("submitBugReport")
var params = [
MultipartFormData(key: "text", type: .text(value: text))
]
var params = [MultipartFormData(key: "text", type: .text(value: text))]
params.append(contentsOf: defaultParams)
for label in githubLabels {
params.append(MultipartFormData(key: "label", type: .text(value: label)))
@@ -140,6 +136,8 @@ class BugReportService: BugReportServiceProtocol {
lastCrashEventId = nil
}
MXLog.info("Feedback submitted.")
return result
}
@@ -176,7 +174,7 @@ class BugReportService: BugReportServiceProtocol {
private func zipFiles(includeLogs: Bool,
includeCrashLog: Bool) async throws -> [URL] {
MXLog.debug("zipFiles: includeLogs: \(includeLogs), includeCrashLog: \(includeCrashLog)")
MXLog.info("zipFiles: includeLogs: \(includeLogs), includeCrashLog: \(includeCrashLog)")
var filesToCompress: [URL] = []
if includeLogs {
@@ -213,7 +211,7 @@ class BugReportService: BugReportServiceProtocol {
zippedFiles.append(zippedFileURL)
}
MXLog.debug("zipFiles: totalSize: \(totalSize), totalZippedSize: \(totalZippedSize)")
MXLog.info("zipFiles: totalSize: \(totalSize), totalZippedSize: \(totalZippedSize)")
return zippedFiles
}
@@ -31,21 +31,21 @@ private class SlidingSyncViewObserver: SlidingSyncViewRoomListObserver, SlidingS
// MARK: - SlidingSyncViewRoomListObserver
func didReceiveUpdate(diff: SlidingSyncViewRoomsListDiff) {
MXLog.verbose("Received room diff")
MXLog.info("Received room diff")
roomListDiffPublisher.send(diff)
}
// MARK: - SlidingSyncViewStateObserver
func didReceiveUpdate(newState: SlidingSyncState) {
MXLog.verbose("Updated state: \(newState)")
MXLog.info("Updated state: \(newState)")
stateUpdatePublisher.send(newState)
}
// MARK: - SlidingSyncViewRoomsCountObserver
func didReceiveUpdate(count: UInt32) {
MXLog.verbose("Updated room count: \(count)")
MXLog.info("Updated room count: \(count)")
countUpdatePublisher.send(UInt(count))
}
}
@@ -49,12 +49,12 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
Task {
do {
let granted = try await notificationCenter.requestAuthorization(options: [.alert, .sound, .badge])
MXLog.debug("[NotificationManager] permission granted: \(granted)")
MXLog.info("[NotificationManager] permission granted: \(granted)")
await MainActor.run {
self.delegate?.authorizationStatusUpdated(self, granted: granted)
}
} catch {
MXLog.debug("[NotificationManager] request authorization failed: \(error)")
MXLog.error("[NotificationManager] request authorization failed: \(error)")
}
}
}
@@ -76,9 +76,9 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
trigger: nil)
do {
try await notificationCenter.add(request)
MXLog.debug("[NotificationManager] show local notification succeeded")
MXLog.info("[NotificationManager] show local notification succeeded")
} catch {
MXLog.debug("[NotificationManager] show local notification failed: \(error)")
MXLog.error("[NotificationManager] show local notification failed: \(error)")
}
}
@@ -102,10 +102,10 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
]
]
])
MXLog.debug("[NotificationManager] set pusher succeeded")
MXLog.info("[NotificationManager] set pusher succeeded")
return true
} catch {
MXLog.debug("[NotificationManager] set pusher failed: \(error)")
MXLog.error("[NotificationManager] set pusher failed: \(error)")
return false
}
}
@@ -83,7 +83,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
MXLog.verbose("Updating \(identifiers.count) rooms")
guard statePublisher.value == .live else {
MXLog.verbose("Sliding sync not live yet, ignoring.")
MXLog.warning("Sliding sync not live yet, ignoring update.")
return
}
@@ -53,7 +53,8 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
switch await roomProxy.addTimelineListener(listener: roomTimelineListener) {
case .failure:
MXLog.error("Failed adding timeline listener on room with identifier: \(await roomProxy.id)")
let roomID = await roomProxy.id
MXLog.error("Failed adding timeline listener on room with identifier: \(roomID)")
default:
break
}
@@ -146,6 +146,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func sendMessage(_ message: String) async {
MXLog.info("Send message in \(roomId)")
switch await timelineProvider.sendMessage(message) {
default:
break
@@ -153,6 +154,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func sendReply(_ message: String, to itemId: String) async {
MXLog.info("Send reply in \(roomId)")
switch await timelineProvider.sendMessage(message, inReplyToItemId: itemId) {
default:
break
@@ -160,6 +162,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func sendReaction(_ reaction: String, for itemId: String) async {
MXLog.info("Send reaction in \(roomId)")
switch await timelineProvider.sendReaction(reaction, for: itemId) {
default:
break
@@ -167,6 +170,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func editMessage(_ newMessage: String, of itemId: String) async {
MXLog.info("Edit message in \(roomId)")
switch await timelineProvider.editMessage(newMessage, originalItemId: itemId) {
default:
break
@@ -174,6 +178,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func redact(_ eventID: String) async {
MXLog.info("Send redaction in \(roomId)")
switch await timelineProvider.redact(eventID) {
default:
break
@@ -0,0 +1,55 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import MatrixRustSDK
// MARK: Redact message content from logs
extension EmoteMessageContent: CustomStringConvertible {
public var description: String {
String(describing: Self.self)
}
}
extension FileMessageContent: CustomStringConvertible {
public var description: String {
String(describing: Self.self)
}
}
extension ImageMessageContent: CustomStringConvertible {
public var description: String {
String(describing: Self.self)
}
}
extension NoticeMessageContent: CustomStringConvertible {
public var description: String {
String(describing: Self.self)
}
}
extension TextMessageContent: CustomStringConvertible {
public var description: String {
String(describing: Self.self)
}
}
extension VideoMessageContent: CustomStringConvertible {
public var description: String {
String(describing: Self.self)
}
}
@@ -19,7 +19,8 @@ import Foundation
import MatrixRustSDK
/// A protocol that contains the base `m.room.message` event content properties.
protocol MessageContentProtocol: RoomMessageEventContentProtocol {
/// The `CustomStringConvertible` conformance is to redact specific properties from the logs.
protocol MessageContentProtocol: RoomMessageEventContentProtocol, CustomStringConvertible {
var body: String { get }
}
@@ -14,7 +14,6 @@
// limitations under the License.
//
import Foundation
import UIKit
struct EmoteRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
@@ -32,3 +31,11 @@ struct EmoteRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hash
var properties = RoomTimelineItemProperties()
}
// MARK: - Redact content from logs
extension EmoteRoomTimelineItem: CustomStringConvertible {
var description: String {
"\(String(describing: Self.self)): id: \(id), timestamp: \(timestamp), isOutgoing: \(isOutgoing), properties: \(properties)"
}
}
@@ -14,7 +14,6 @@
// limitations under the License.
//
import Foundation
import UIKit
struct FileRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
@@ -35,3 +34,11 @@ struct FileRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hasha
var properties = RoomTimelineItemProperties()
}
// MARK: - Redact content from logs
extension FileRoomTimelineItem: CustomStringConvertible {
var description: String {
"\(String(describing: Self.self)): id: \(id), timestamp: \(timestamp), isOutgoing: \(isOutgoing), properties: \(properties)"
}
}
@@ -14,7 +14,6 @@
// limitations under the License.
//
import Foundation
import UIKit
struct ImageRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
@@ -40,3 +39,11 @@ struct ImageRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hash
var properties = RoomTimelineItemProperties()
}
// MARK: - Redact content from logs
extension ImageRoomTimelineItem: CustomStringConvertible {
var description: String {
"\(String(describing: Self.self)): id: \(id), timestamp: \(timestamp), isOutgoing: \(isOutgoing), properties: \(properties)"
}
}
@@ -14,7 +14,6 @@
// limitations under the License.
//
import Foundation
import UIKit
struct NoticeRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
@@ -32,3 +31,11 @@ struct NoticeRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Has
var properties = RoomTimelineItemProperties()
}
// MARK: - Redact content from logs
extension NoticeRoomTimelineItem: CustomStringConvertible {
var description: String {
"\(String(describing: Self.self)): id: \(id), timestamp: \(timestamp), isOutgoing: \(isOutgoing), properties: \(properties)"
}
}
@@ -14,7 +14,6 @@
// limitations under the License.
//
import Foundation
import UIKit
struct TextRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
@@ -32,3 +31,11 @@ struct TextRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hasha
var properties = RoomTimelineItemProperties()
}
// MARK: - Redact content from logs
extension TextRoomTimelineItem: CustomStringConvertible {
var description: String {
"\(String(describing: Self.self)): id: \(id), timestamp: \(timestamp), isOutgoing: \(isOutgoing), properties: \(properties)"
}
}
@@ -14,7 +14,6 @@
// limitations under the License.
//
import Foundation
import UIKit
struct VideoRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
@@ -42,3 +41,11 @@ struct VideoRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hash
var properties = RoomTimelineItemProperties()
}
// MARK: - Redact content from logs
extension VideoRoomTimelineItem: CustomStringConvertible {
var description: String {
"\(String(describing: Self.self)): id: \(id), timestamp: \(timestamp), isOutgoing: \(isOutgoing), properties: \(properties)"
}
}
@@ -33,7 +33,7 @@ class UserSessionStore: UserSessionStoreProtocol {
accessGroup: InfoPlistReader.target.keychainAccessGroupIdentifier)
self.backgroundTaskService = backgroundTaskService
baseDirectory = .sessionsBaseDirectory
MXLog.debug("Setup base directory at: \(baseDirectory)")
MXLog.info("Setup base directory at: \(baseDirectory)")
}
/// Deletes all data stored in the shared container and keychain