mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Various logging fixes (#164)
Various logging fixes: * imported the ObjCWrapper and updated the MXLogger. Also added back support for app containers * updated MXLog.swift from El and fixed/improved its logging format * updated most app log strings * Remove unnecessary swiftlint rule * Various tweaks following code review * Added back type annoation on MXLogger logFiles method * Fix generated Swift-ObjC header name
This commit is contained in:
@@ -57,7 +57,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
|
||||
}
|
||||
|
||||
if identifier == .invalid {
|
||||
MXLog.verbose("[UIKitBackgroundTask] Do not start background task: \(name), as OS declined")
|
||||
MXLog.verbose("Do not start background task: \(name), as OS declined")
|
||||
// call expiration handler immediately
|
||||
expirationHandler?(self)
|
||||
return nil
|
||||
@@ -68,7 +68,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
|
||||
reuse()
|
||||
}
|
||||
|
||||
MXLog.verbose("[UIKitBackgroundTask] Start background task #\(identifier.rawValue) - \(name)")
|
||||
MXLog.verbose("Start background task #\(identifier.rawValue) - \(name)")
|
||||
}
|
||||
|
||||
func reuse() {
|
||||
@@ -91,7 +91,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
|
||||
|
||||
private func endTask() {
|
||||
if identifier != .invalid {
|
||||
MXLog.verbose("[UIKitBackgroundTask] End background task #\(identifier.rawValue) - \(name) after \(readableElapsedTime)")
|
||||
MXLog.verbose("End background task #\(identifier.rawValue) - \(name) after \(readableElapsedTime)")
|
||||
|
||||
application.endBackgroundTask(identifier)
|
||||
identifier = .invalid
|
||||
|
||||
@@ -32,12 +32,12 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol {
|
||||
isReusable: Bool,
|
||||
expirationHandler: (() -> Void)?) -> BackgroundTaskProtocol? {
|
||||
guard let application = application else {
|
||||
MXLog.verbose("[UIKitBackgroundTaskService] Do not start background task: \(name). Application is nil")
|
||||
MXLog.verbose("Do not start background task: \(name). Application is nil")
|
||||
return nil
|
||||
}
|
||||
|
||||
if avoidStartingNewTasks(for: application) {
|
||||
MXLog.verbose("[UIKitBackgroundTaskService] Do not start background task: \(name), as not enough time exists")
|
||||
MXLog.verbose("Do not start background task: \(name), as not enough time exists")
|
||||
// call expiration handler immediately
|
||||
expirationHandler?()
|
||||
return nil
|
||||
@@ -78,7 +78,7 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol {
|
||||
let appState = application.applicationState
|
||||
let remainingTime = readableBackgroundTimeRemaining(application.backgroundTimeRemaining)
|
||||
|
||||
MXLog.verbose("[UIKitBackgroundTaskService] Background task \(name) \(created ? "started" : "reused") with app state: \(appState) and estimated background time remaining: \(remainingTime)")
|
||||
MXLog.verbose("Background task \(name) \(created ? "started" : "reused") with app state: \(appState) and estimated background time remaining: \(remainingTime)")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class BugReportService: BugReportServiceProtocol {
|
||||
private let sentryEndpoint: String
|
||||
private let applicationId: String
|
||||
private let session: URLSession
|
||||
private var lastCrashEventId: String?
|
||||
|
||||
init(withBaseUrlString baseUrlString: String,
|
||||
sentryEndpoint: String,
|
||||
@@ -63,8 +64,9 @@ class BugReportService: BugReportServiceProtocol {
|
||||
return event
|
||||
}
|
||||
|
||||
options.onCrashedLastRun = { event in
|
||||
options.onCrashedLastRun = { [weak self] event in
|
||||
MXLog.debug("Sentry detected application was crashed: \(event)")
|
||||
self?.lastCrashEventId = event.eventId.sentryIdString
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,12 +86,13 @@ class BugReportService: BugReportServiceProtocol {
|
||||
SentrySDK.crash()
|
||||
}
|
||||
|
||||
// swiftlint: disable function_body_length
|
||||
func submitBugReport(text: String,
|
||||
includeLogs: Bool,
|
||||
includeCrashLog: Bool,
|
||||
githubLabels: [String],
|
||||
files: [URL]) async throws -> SubmitBugReportResponse {
|
||||
MXLog.debug("[BugReportService] submitBugReport")
|
||||
MXLog.debug("submitBugReport")
|
||||
|
||||
var params = [
|
||||
MultipartFormData(key: "text", type: .text(value: text))
|
||||
@@ -106,6 +109,11 @@ class BugReportService: BugReportServiceProtocol {
|
||||
params.append(MultipartFormData(key: "compressed-log", type: .file(url: url)))
|
||||
}
|
||||
}
|
||||
|
||||
if let crashEventId = lastCrashEventId {
|
||||
params.append(MultipartFormData(key: "crash_report", type: .text(value: "<https://sentry.tools.element.io/organizations/element/issues/?project=44&query=\(crashEventId)>")))
|
||||
}
|
||||
|
||||
for url in files {
|
||||
params.append(MultipartFormData(key: "file", type: .file(url: url)))
|
||||
}
|
||||
@@ -142,9 +150,11 @@ class BugReportService: BugReportServiceProtocol {
|
||||
|
||||
if !result.reportUrl.isEmpty {
|
||||
MXLogger.deleteCrashLog()
|
||||
lastCrashEventId = nil
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
} // swiftlint: enable function_body_length
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -179,7 +189,7 @@ class BugReportService: BugReportServiceProtocol {
|
||||
|
||||
private func zipFiles(includeLogs: Bool,
|
||||
includeCrashLog: Bool) async throws -> [URL] {
|
||||
MXLog.debug("[BugReportService] zipFiles: includeLogs: \(includeLogs), includeCrashLog: \(includeCrashLog)")
|
||||
MXLog.debug("zipFiles: includeLogs: \(includeLogs), includeCrashLog: \(includeCrashLog)")
|
||||
|
||||
var filesToCompress: [URL] = []
|
||||
if includeLogs, let logFiles = MXLogger.logFiles() {
|
||||
@@ -217,7 +227,7 @@ class BugReportService: BugReportServiceProtocol {
|
||||
zippedFiles.append(zippedFileURL)
|
||||
}
|
||||
|
||||
MXLog.debug("[BugReportService] zipFiles: totalSize: \(totalSize), totalZippedSize: \(totalZippedSize)")
|
||||
MXLog.debug("zipFiles: totalSize: \(totalSize), totalZippedSize: \(totalZippedSize)")
|
||||
|
||||
return zippedFiles
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import Foundation
|
||||
|
||||
extension FileManager {
|
||||
/// The URL of the primary app group container.
|
||||
var appGroupContainerURL: URL? {
|
||||
@objc var appGroupContainerURL: URL? {
|
||||
containerURL(forSecurityApplicationGroupIdentifier: ElementInfoPlist.appGroupIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user