Expose the log level in developer settings

This commit is contained in:
Stefan Ceriu 2023-08-23 14:58:44 +03:00 committed by Stefan Ceriu
parent beeb5fc83c
commit a19f5a4186
9 changed files with 44 additions and 39 deletions

View File

@ -57,11 +57,16 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
@Consumable private var storedAppRoute: AppRoute? @Consumable private var storedAppRoute: AppRoute?
init() { 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() navigationRootCoordinator = NavigationRootCoordinator()
Self.setupServiceLocator(navigationRootCoordinator: navigationRootCoordinator) Self.setupServiceLocator(navigationRootCoordinator: navigationRootCoordinator, appSettings: appSettings)
ServiceLocator.shared.analytics.startIfEnabled() ServiceLocator.shared.analytics.startIfEnabled()
@ -191,13 +196,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
// MARK: - Private // MARK: - Private
private static func setupServiceLocator(navigationRootCoordinator: NavigationRootCoordinator) { private static func setupServiceLocator(navigationRootCoordinator: NavigationRootCoordinator, appSettings: AppSettings) {
if ProcessInfo.processInfo.environment["RESET_APP_SETTINGS"].map(Bool.init) == true {
AppSettings.reset()
}
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController(rootCoordinator: navigationRootCoordinator)) 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(networkMonitor: NetworkMonitor())
ServiceLocator.shared.register(bugReportService: BugReportService(withBaseURL: ServiceLocator.shared.settings.bugReportServiceBaseURL, ServiceLocator.shared.register(bugReportService: BugReportService(withBaseURL: ServiceLocator.shared.settings.bugReportServiceBaseURL,
sentryURL: ServiceLocator.shared.settings.bugReportSentryURL, sentryURL: ServiceLocator.shared.settings.bugReportSentryURL,

View File

@ -29,6 +29,7 @@ final class AppSettings {
case enableNotifications case enableNotifications
case enableInAppNotifications case enableInAppNotifications
case pusherProfileTag case pusherProfileTag
case logLevel
// Feature flags // Feature flags
case shouldCollapseRoomStateEvents case shouldCollapseRoomStateEvents
@ -196,6 +197,9 @@ final class AppSettings {
let permalinkBaseURL: URL = "https://matrix.to" let permalinkBaseURL: URL = "https://matrix.to"
@UserPreference(key: UserDefaultsKeys.logLevel, defaultValue: TracingConfiguration.LogLevel.info, storageType: .userDefaults(store))
var logLevel
// MARK: - Maps // MARK: - Maps
// maptiler base url // maptiler base url

View File

@ -42,7 +42,7 @@ enum MXLog {
private static var target: String! private static var target: String!
static func configure(target: String? = nil, static func configure(target: String? = nil,
logLevel: TracingConfiguration.LogLevel? = nil, logLevel: TracingConfiguration.LogLevel,
redirectToFiles: Bool = Constants.redirectToFiles, redirectToFiles: Bool = Constants.redirectToFiles,
maxLogFileCount: UInt = Constants.maxLogFileCount, maxLogFileCount: UInt = Constants.maxLogFileCount,
logFileSizeLimit: UInt = Constants.logFilesSizeLimit) { logFileSizeLimit: UInt = Constants.logFilesSizeLimit) {
@ -58,15 +58,7 @@ enum MXLog {
return return
} }
if let logLevel { setupTracing(configuration: .custom(logLevel: logLevel))
setupTracing(configuration: .custom(logLevel: logLevel))
} else {
#if DEBUG
setupTracing(configuration: .debug)
#else
setupTracing(configuration: .release)
#endif
}
if let target { if let target {
self.target = target self.target = target

View File

@ -21,10 +21,6 @@ import MatrixRustSDK
// We can filter by level, crate and even file. See more details here: // 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 // https://docs.rs/tracing-subscriber/0.2.7/tracing_subscriber/filter/struct.EnvFilter.html#examples
struct TracingConfiguration { struct TracingConfiguration {
static var release = TracingConfiguration(overrides: [.common: .info])
static var debug = TracingConfiguration(overrides: [.common: .info])
/// Configure tracing with certain overrides in place /// Configure tracing with certain overrides in place
/// - Parameter overrides: the desired overrides /// - Parameter overrides: the desired overrides
/// - Returns: a custom tracing configuration /// - Returns: a custom tracing configuration
@ -43,7 +39,7 @@ struct TracingConfiguration {
return TracingConfiguration(overrides: overrides) 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 { enum Target: String {
case common = "" case common = ""
@ -59,11 +55,11 @@ struct TracingConfiguration {
static let targets: OrderedDictionary<Target, LogLevel> = [ static let targets: OrderedDictionary<Target, LogLevel> = [
.common: .info, .common: .info,
.hyper: .warn, .hyper: .info,
.matrix_sdk_crypto: .debug, .matrix_sdk_crypto: .info,
.matrix_sdk_http_client: .debug, .matrix_sdk_http_client: .info,
.matrix_sdk_sliding_sync: .debug, .matrix_sdk_sliding_sync: .info,
.matrix_sdk_base_sliding_sync: .debug, .matrix_sdk_base_sliding_sync: .info,
.matrix_sdk_ui_timeline: .info .matrix_sdk_ui_timeline: .info
] ]

View File

@ -18,7 +18,9 @@ import SwiftUI
struct PillView: View { struct PillView: View {
var body: some View { var body: some View {
Button(action: { MXLog.info("TEXT ATTACHMENT TEST") }) { Button {
MXLog.info("TEXT ATTACHMENT TEST")
} label: {
HStack { HStack {
Image(asset: Asset.Images.launchLogo) Image(asset: Asset.Images.launchLogo)
.resizable() .resizable()

View File

@ -43,6 +43,7 @@ enum DeveloperOptionsScreenViewAction {
} }
protocol DeveloperOptionsProtocol: AnyObject { protocol DeveloperOptionsProtocol: AnyObject {
var logLevel: TracingConfiguration.LogLevel { get set }
var shouldCollapseRoomStateEvents: Bool { get set } var shouldCollapseRoomStateEvents: Bool { get set }
var userSuggestionsEnabled: Bool { get set } var userSuggestionsEnabled: Bool { get set }
var readReceiptsEnabled: Bool { get set } var readReceiptsEnabled: Bool { get set }

View File

@ -22,6 +22,15 @@ struct DeveloperOptionsScreen: View {
var body: some View { var body: some View {
Form { 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") { Section("Timeline") {
Toggle(isOn: $context.shouldCollapseRoomStateEvents) { Toggle(isOn: $context.shouldCollapseRoomStateEvents) {
Text("Collapse room state events") Text("Collapse room state events")

View File

@ -81,7 +81,7 @@ class NSELogger {
} }
isConfigured = true isConfigured = true
MXLog.configure(target: "nse") MXLog.configure(target: "nse", logLevel: .info)
} }
static func logMemory(with tag: String) { static func logMemory(with tag: String) {

View File

@ -36,7 +36,7 @@ class LoggingTests: XCTestCase {
let log = UUID().uuidString let log = UUID().uuidString
MXLog.configure(redirectToFiles: true) MXLog.configure(logLevel: .info, redirectToFiles: true)
MXLog.info(log) MXLog.info(log)
guard let logFile = MXLogger.logFiles.first else { guard let logFile = MXLogger.logFiles.first else {
@ -55,7 +55,7 @@ class LoggingTests: XCTestCase {
// When launching the app 5 times. // When launching the app 5 times.
let launchCount = 5 let launchCount = 5
for index in 0..<launchCount { for index in 0..<launchCount {
MXLog.configure(redirectToFiles: true) MXLog.configure(logLevel: .info, redirectToFiles: true)
MXLog.info("Launch \(index + 1)") MXLog.info("Launch \(index + 1)")
} }
@ -74,7 +74,7 @@ class LoggingTests: XCTestCase {
let launchCount = 10 let launchCount = 10
let logFileCount = 5 let logFileCount = 5
for index in 0..<launchCount { 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)") MXLog.info("Launch \(index + 1)")
} }
@ -93,7 +93,7 @@ class LoggingTests: XCTestCase {
let launchCount = 10 let launchCount = 10
let logFileSizeLimit: UInt = 25 * 1024 let logFileSizeLimit: UInt = 25 * 1024
for index in 0..<launchCount { for index in 0..<launchCount {
MXLog.configure(redirectToFiles: true, logFileSizeLimit: logFileSizeLimit) MXLog.configure(logLevel: .info, redirectToFiles: true, logFileSizeLimit: logFileSizeLimit)
MXLog.info("Launch \(index + 1)") MXLog.info("Launch \(index + 1)")
// Add ~5KB of logs // Add ~5KB of logs
@ -133,7 +133,7 @@ class LoggingTests: XCTestCase {
let log = UUID().uuidString let log = UUID().uuidString
MXLog.configure(redirectToFiles: true) MXLog.configure(logLevel: .info, redirectToFiles: true)
MXLog.verbose(log) MXLog.verbose(log)
guard let logFile = MXLogger.logFiles.first else { guard let logFile = MXLogger.logFiles.first else {
@ -150,7 +150,7 @@ class LoggingTests: XCTestCase {
let target = "nse" let target = "nse"
MXLog.configure(target: target, redirectToFiles: true) MXLog.configure(target: target, logLevel: .info, redirectToFiles: true)
MXLog.info(UUID().uuidString) MXLog.info(UUID().uuidString)
guard let logFile = MXLogger.logFiles.first else { guard let logFile = MXLogger.logFiles.first else {
@ -233,7 +233,7 @@ class LoggingTests: XCTestCase {
// When logging that value // When logging that value
XCTAssert(MXLogger.logFiles.isEmpty) XCTAssert(MXLogger.logFiles.isEmpty)
MXLog.configure(redirectToFiles: true) MXLog.configure(logLevel: .info, redirectToFiles: true)
MXLog.info(roomSummary) MXLog.info(roomSummary)
@ -294,7 +294,7 @@ class LoggingTests: XCTestCase {
// When logging that value // When logging that value
XCTAssert(MXLogger.logFiles.isEmpty) XCTAssert(MXLogger.logFiles.isEmpty)
MXLog.configure(redirectToFiles: true) MXLog.configure(logLevel: .info, redirectToFiles: true)
MXLog.info(textMessage) MXLog.info(textMessage)
MXLog.info(noticeMessage) MXLog.info(noticeMessage)
@ -352,7 +352,7 @@ class LoggingTests: XCTestCase {
// When logging that value // When logging that value
XCTAssert(MXLogger.logFiles.isEmpty) XCTAssert(MXLogger.logFiles.isEmpty)
MXLog.configure(redirectToFiles: true) MXLog.configure(logLevel: .info, redirectToFiles: true)
MXLog.info(textMessage) MXLog.info(textMessage)
MXLog.info(noticeMessage) MXLog.info(noticeMessage)