mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Expose the log level in developer settings
This commit is contained in:
parent
beeb5fc83c
commit
a19f5a4186
@ -57,11 +57,16 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
||||
@Consumable private var storedAppRoute: AppRoute?
|
||||
|
||||
init() {
|
||||
MXLog.configure()
|
||||
let appSettings = AppSettings()
|
||||
MXLog.configure(logLevel: appSettings.logLevel)
|
||||
|
||||
if ProcessInfo.processInfo.environment["RESET_APP_SETTINGS"].map(Bool.init) == true {
|
||||
AppSettings.reset()
|
||||
}
|
||||
|
||||
navigationRootCoordinator = NavigationRootCoordinator()
|
||||
|
||||
Self.setupServiceLocator(navigationRootCoordinator: navigationRootCoordinator)
|
||||
Self.setupServiceLocator(navigationRootCoordinator: navigationRootCoordinator, appSettings: appSettings)
|
||||
|
||||
ServiceLocator.shared.analytics.startIfEnabled()
|
||||
|
||||
@ -191,13 +196,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private static func setupServiceLocator(navigationRootCoordinator: NavigationRootCoordinator) {
|
||||
if ProcessInfo.processInfo.environment["RESET_APP_SETTINGS"].map(Bool.init) == true {
|
||||
AppSettings.reset()
|
||||
}
|
||||
|
||||
private static func setupServiceLocator(navigationRootCoordinator: NavigationRootCoordinator, appSettings: AppSettings) {
|
||||
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController(rootCoordinator: navigationRootCoordinator))
|
||||
ServiceLocator.shared.register(appSettings: AppSettings())
|
||||
ServiceLocator.shared.register(appSettings: appSettings)
|
||||
ServiceLocator.shared.register(networkMonitor: NetworkMonitor())
|
||||
ServiceLocator.shared.register(bugReportService: BugReportService(withBaseURL: ServiceLocator.shared.settings.bugReportServiceBaseURL,
|
||||
sentryURL: ServiceLocator.shared.settings.bugReportSentryURL,
|
||||
|
@ -29,6 +29,7 @@ final class AppSettings {
|
||||
case enableNotifications
|
||||
case enableInAppNotifications
|
||||
case pusherProfileTag
|
||||
case logLevel
|
||||
|
||||
// Feature flags
|
||||
case shouldCollapseRoomStateEvents
|
||||
@ -196,6 +197,9 @@ final class AppSettings {
|
||||
|
||||
let permalinkBaseURL: URL = "https://matrix.to"
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.logLevel, defaultValue: TracingConfiguration.LogLevel.info, storageType: .userDefaults(store))
|
||||
var logLevel
|
||||
|
||||
// MARK: - Maps
|
||||
|
||||
// maptiler base url
|
||||
|
@ -42,7 +42,7 @@ enum MXLog {
|
||||
private static var target: String!
|
||||
|
||||
static func configure(target: String? = nil,
|
||||
logLevel: TracingConfiguration.LogLevel? = nil,
|
||||
logLevel: TracingConfiguration.LogLevel,
|
||||
redirectToFiles: Bool = Constants.redirectToFiles,
|
||||
maxLogFileCount: UInt = Constants.maxLogFileCount,
|
||||
logFileSizeLimit: UInt = Constants.logFilesSizeLimit) {
|
||||
@ -58,15 +58,7 @@ enum MXLog {
|
||||
return
|
||||
}
|
||||
|
||||
if let logLevel {
|
||||
setupTracing(configuration: .custom(logLevel: logLevel))
|
||||
} else {
|
||||
#if DEBUG
|
||||
setupTracing(configuration: .debug)
|
||||
#else
|
||||
setupTracing(configuration: .release)
|
||||
#endif
|
||||
}
|
||||
setupTracing(configuration: .custom(logLevel: logLevel))
|
||||
|
||||
if let target {
|
||||
self.target = target
|
||||
|
@ -21,10 +21,6 @@ import MatrixRustSDK
|
||||
// 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
|
||||
struct TracingConfiguration {
|
||||
static var release = TracingConfiguration(overrides: [.common: .info])
|
||||
|
||||
static var debug = TracingConfiguration(overrides: [.common: .info])
|
||||
|
||||
/// Configure tracing with certain overrides in place
|
||||
/// - Parameter overrides: the desired overrides
|
||||
/// - Returns: a custom tracing configuration
|
||||
@ -43,7 +39,7 @@ struct TracingConfiguration {
|
||||
return TracingConfiguration(overrides: overrides)
|
||||
}
|
||||
|
||||
enum LogLevel: String { case error, warn, info, debug, trace }
|
||||
enum LogLevel: String, Codable, CaseIterable { case error, warn, info, debug, trace }
|
||||
|
||||
enum Target: String {
|
||||
case common = ""
|
||||
@ -59,11 +55,11 @@ struct TracingConfiguration {
|
||||
|
||||
static let targets: OrderedDictionary<Target, LogLevel> = [
|
||||
.common: .info,
|
||||
.hyper: .warn,
|
||||
.matrix_sdk_crypto: .debug,
|
||||
.matrix_sdk_http_client: .debug,
|
||||
.matrix_sdk_sliding_sync: .debug,
|
||||
.matrix_sdk_base_sliding_sync: .debug,
|
||||
.hyper: .info,
|
||||
.matrix_sdk_crypto: .info,
|
||||
.matrix_sdk_http_client: .info,
|
||||
.matrix_sdk_sliding_sync: .info,
|
||||
.matrix_sdk_base_sliding_sync: .info,
|
||||
.matrix_sdk_ui_timeline: .info
|
||||
]
|
||||
|
||||
|
@ -18,7 +18,9 @@ import SwiftUI
|
||||
|
||||
struct PillView: View {
|
||||
var body: some View {
|
||||
Button(action: { MXLog.info("TEXT ATTACHMENT TEST") }) {
|
||||
Button {
|
||||
MXLog.info("TEXT ATTACHMENT TEST")
|
||||
} label: {
|
||||
HStack {
|
||||
Image(asset: Asset.Images.launchLogo)
|
||||
.resizable()
|
||||
|
@ -43,6 +43,7 @@ enum DeveloperOptionsScreenViewAction {
|
||||
}
|
||||
|
||||
protocol DeveloperOptionsProtocol: AnyObject {
|
||||
var logLevel: TracingConfiguration.LogLevel { get set }
|
||||
var shouldCollapseRoomStateEvents: Bool { get set }
|
||||
var userSuggestionsEnabled: Bool { get set }
|
||||
var readReceiptsEnabled: Bool { get set }
|
||||
|
@ -22,6 +22,15 @@ struct DeveloperOptionsScreen: View {
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Picker(selection: $context.logLevel) {
|
||||
ForEach(TracingConfiguration.LogLevel.allCases, id: \.self) { logLevel in
|
||||
Text(logLevel.rawValue.capitalized)
|
||||
}
|
||||
} label: {
|
||||
Text("Log level")
|
||||
Text("Requires app reboot")
|
||||
}
|
||||
|
||||
Section("Timeline") {
|
||||
Toggle(isOn: $context.shouldCollapseRoomStateEvents) {
|
||||
Text("Collapse room state events")
|
||||
|
@ -81,7 +81,7 @@ class NSELogger {
|
||||
}
|
||||
isConfigured = true
|
||||
|
||||
MXLog.configure(target: "nse")
|
||||
MXLog.configure(target: "nse", logLevel: .info)
|
||||
}
|
||||
|
||||
static func logMemory(with tag: String) {
|
||||
|
@ -36,7 +36,7 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
let log = UUID().uuidString
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true)
|
||||
|
||||
MXLog.info(log)
|
||||
guard let logFile = MXLogger.logFiles.first else {
|
||||
@ -55,7 +55,7 @@ class LoggingTests: XCTestCase {
|
||||
// When launching the app 5 times.
|
||||
let launchCount = 5
|
||||
for index in 0..<launchCount {
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true)
|
||||
MXLog.info("Launch \(index + 1)")
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ class LoggingTests: XCTestCase {
|
||||
let launchCount = 10
|
||||
let logFileCount = 5
|
||||
for index in 0..<launchCount {
|
||||
MXLog.configure(redirectToFiles: true, maxLogFileCount: UInt(logFileCount))
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true, maxLogFileCount: UInt(logFileCount))
|
||||
MXLog.info("Launch \(index + 1)")
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ class LoggingTests: XCTestCase {
|
||||
let launchCount = 10
|
||||
let logFileSizeLimit: UInt = 25 * 1024
|
||||
for index in 0..<launchCount {
|
||||
MXLog.configure(redirectToFiles: true, logFileSizeLimit: logFileSizeLimit)
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true, logFileSizeLimit: logFileSizeLimit)
|
||||
MXLog.info("Launch \(index + 1)")
|
||||
|
||||
// Add ~5KB of logs
|
||||
@ -133,7 +133,7 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
let log = UUID().uuidString
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true)
|
||||
|
||||
MXLog.verbose(log)
|
||||
guard let logFile = MXLogger.logFiles.first else {
|
||||
@ -150,7 +150,7 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
let target = "nse"
|
||||
|
||||
MXLog.configure(target: target, redirectToFiles: true)
|
||||
MXLog.configure(target: target, logLevel: .info, redirectToFiles: true)
|
||||
|
||||
MXLog.info(UUID().uuidString)
|
||||
guard let logFile = MXLogger.logFiles.first else {
|
||||
@ -233,7 +233,7 @@ class LoggingTests: XCTestCase {
|
||||
// When logging that value
|
||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true)
|
||||
|
||||
MXLog.info(roomSummary)
|
||||
|
||||
@ -294,7 +294,7 @@ class LoggingTests: XCTestCase {
|
||||
// When logging that value
|
||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true)
|
||||
|
||||
MXLog.info(textMessage)
|
||||
MXLog.info(noticeMessage)
|
||||
@ -352,7 +352,7 @@ class LoggingTests: XCTestCase {
|
||||
// When logging that value
|
||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: true)
|
||||
|
||||
MXLog.info(textMessage)
|
||||
MXLog.info(noticeMessage)
|
||||
|
Loading…
x
Reference in New Issue
Block a user