mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Setup tracing through the RustSDK (#146)
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Combine
|
import Combine
|
||||||
|
import MatrixRustSDK
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
|
class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
|
||||||
@@ -71,13 +72,7 @@ class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
|
|||||||
|
|
||||||
setupStateMachine()
|
setupStateMachine()
|
||||||
|
|
||||||
let loggerConfiguration = MXLogConfiguration()
|
setupLogging()
|
||||||
loggerConfiguration.logLevel = .verbose
|
|
||||||
// Redirect NSLogs to files only if we are not debugging
|
|
||||||
if isatty(STDERR_FILENO) == 0 {
|
|
||||||
loggerConfiguration.redirectLogsToFiles = true
|
|
||||||
}
|
|
||||||
MXLog.configure(loggerConfiguration)
|
|
||||||
|
|
||||||
// Benchmark.trackingEnabled = true
|
// Benchmark.trackingEnabled = true
|
||||||
}
|
}
|
||||||
@@ -97,6 +92,29 @@ class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
|
|||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
|
private func setupLogging() {
|
||||||
|
let loggerConfiguration = MXLogConfiguration()
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
// This exposes the full Rust side tracing subscriber filter for more flexibility.
|
||||||
|
// We can filter by level, crate and even file. See more details here:
|
||||||
|
// https://docs.rs/tracing-subscriber/0.2.7/tracing_subscriber/filter/struct.EnvFilter.html#examples
|
||||||
|
setupTracing(configuration: "info,hyper=warn,sled=warn,matrix_sdk_sled=warn")
|
||||||
|
|
||||||
|
loggerConfiguration.logLevel = .debug
|
||||||
|
#else
|
||||||
|
setupTracing(configuration: "info,hyper=warn,sled=warn,matrix_sdk_sled=warn")
|
||||||
|
loggerConfiguration.logLevel = .info
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Avoid redirecting NSLogs to files if we are attached to a debugger.
|
||||||
|
if isatty(STDERR_FILENO) == 0 {
|
||||||
|
loggerConfiguration.redirectLogsToFiles = true
|
||||||
|
}
|
||||||
|
|
||||||
|
MXLog.configure(loggerConfiguration)
|
||||||
|
}
|
||||||
|
|
||||||
// swiftlint:disable cyclomatic_complexity
|
// swiftlint:disable cyclomatic_complexity
|
||||||
private func setupStateMachine() {
|
private func setupStateMachine() {
|
||||||
stateMachine.addTransitionHandler { [weak self] context in
|
stateMachine.addTransitionHandler { [weak self] context in
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if identifier == .invalid {
|
if identifier == .invalid {
|
||||||
MXLog.debug("[UIKitBackgroundTask] Do not start background task: \(name), as OS declined")
|
MXLog.verbose("[UIKitBackgroundTask] Do not start background task: \(name), as OS declined")
|
||||||
// call expiration handler immediately
|
// call expiration handler immediately
|
||||||
expirationHandler?(self)
|
expirationHandler?(self)
|
||||||
return nil
|
return nil
|
||||||
@@ -60,7 +60,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
|
|||||||
reuse()
|
reuse()
|
||||||
}
|
}
|
||||||
|
|
||||||
MXLog.debug("[UIKitBackgroundTask] Start background task #\(identifier.rawValue) - \(name)")
|
MXLog.verbose("[UIKitBackgroundTask] Start background task #\(identifier.rawValue) - \(name)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func reuse() {
|
func reuse() {
|
||||||
@@ -83,7 +83,7 @@ class UIKitBackgroundTask: BackgroundTaskProtocol {
|
|||||||
|
|
||||||
private func endTask() {
|
private func endTask() {
|
||||||
if identifier != .invalid {
|
if identifier != .invalid {
|
||||||
MXLog.debug("[UIKitBackgroundTask] End background task #\(identifier.rawValue) - \(name) after \(readableElapsedTime)")
|
MXLog.verbose("[UIKitBackgroundTask] End background task #\(identifier.rawValue) - \(name) after \(readableElapsedTime)")
|
||||||
|
|
||||||
application.endBackgroundTask(identifier)
|
application.endBackgroundTask(identifier)
|
||||||
identifier = .invalid
|
identifier = .invalid
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol {
|
|||||||
isReusable: Bool,
|
isReusable: Bool,
|
||||||
expirationHandler: (() -> Void)?) -> BackgroundTaskProtocol? {
|
expirationHandler: (() -> Void)?) -> BackgroundTaskProtocol? {
|
||||||
guard let application = application else {
|
guard let application = application else {
|
||||||
MXLog.debug("[UIKitBackgroundTaskService] Do not start background task: \(name). Application is nil")
|
MXLog.verbose("[UIKitBackgroundTaskService] Do not start background task: \(name). Application is nil")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if avoidStartingNewTasks(for: application) {
|
if avoidStartingNewTasks(for: application) {
|
||||||
MXLog.debug("[UIKitBackgroundTaskService] Do not start background task: \(name), as not enough time exists")
|
MXLog.verbose("[UIKitBackgroundTaskService] Do not start background task: \(name), as not enough time exists")
|
||||||
// call expiration handler immediately
|
// call expiration handler immediately
|
||||||
expirationHandler?()
|
expirationHandler?()
|
||||||
return nil
|
return nil
|
||||||
@@ -70,7 +70,7 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol {
|
|||||||
let appState = application.applicationState
|
let appState = application.applicationState
|
||||||
let remainingTime = readableBackgroundTimeRemaining(application.backgroundTimeRemaining)
|
let remainingTime = readableBackgroundTimeRemaining(application.backgroundTimeRemaining)
|
||||||
|
|
||||||
MXLog.debug("[UIKitBackgroundTaskService] Background task \(name) \(created ? "started" : "reused") with app state: \(appState) and estimated background time remaining: \(remainingTime)")
|
MXLog.verbose("[UIKitBackgroundTaskService] Background task \(name) \(created ? "started" : "reused") with app state: \(appState) and estimated background time remaining: \(remainingTime)")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user