mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Allow setting custom log levels (#1592)
* Allow using custom tracing configuration from the developer options screen. Clean up RustTracing * Move log level configurations to a separate view * Disable autocorrection * Fix unit tests * Use TracingConfiguration.info as the default text value, switch to a TextEditor
This commit is contained in:
+47
-9
@@ -19,18 +19,11 @@ import SwiftUI
|
||||
struct DeveloperOptionsScreen: View {
|
||||
@ObservedObject var context: DeveloperOptionsScreenViewModel.Context
|
||||
@State private var showConfetti = false
|
||||
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("Logging") {
|
||||
Picker(selection: $context.logLevel) {
|
||||
ForEach(TracingConfiguration.LogLevel.allCases, id: \.self) { logLevel in
|
||||
Text(logLevel.rawValue.capitalized)
|
||||
}
|
||||
} label: {
|
||||
Text("Log level")
|
||||
Text("Requires app reboot")
|
||||
}
|
||||
LogLevelConfigurationView(logLevel: $context.logLevel)
|
||||
|
||||
Toggle(isOn: $context.otlpTracingEnabled) {
|
||||
Text("OTLP tracing")
|
||||
@@ -130,6 +123,51 @@ struct DeveloperOptionsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private struct LogLevelConfigurationView: View {
|
||||
@Binding var logLevel: TracingConfiguration.LogLevel
|
||||
|
||||
@State private var customTracingConfiguration: String
|
||||
|
||||
init(logLevel: Binding<TracingConfiguration.LogLevel>) {
|
||||
_logLevel = logLevel
|
||||
|
||||
if case .custom(let configuration) = logLevel.wrappedValue {
|
||||
customTracingConfiguration = configuration
|
||||
} else {
|
||||
customTracingConfiguration = TracingConfiguration(logLevel: .info).filter
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Picker(selection: $logLevel) {
|
||||
ForEach(logLevels, id: \.self) { logLevel in
|
||||
Text(logLevel.title)
|
||||
}
|
||||
} label: {
|
||||
Text("Log level")
|
||||
Text("Requires app reboot")
|
||||
}
|
||||
|
||||
if case .custom = logLevel {
|
||||
TextEditor(text: $customTracingConfiguration)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
.onChange(of: customTracingConfiguration) { newValue in
|
||||
logLevel = .custom(newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows the picker to work with associated values
|
||||
private var logLevels: [TracingConfiguration.LogLevel] {
|
||||
if case let .custom(filter) = logLevel {
|
||||
return [.error, .warn, .info, .debug, .trace, .custom(filter)]
|
||||
} else {
|
||||
return [.error, .warn, .info, .debug, .trace, .custom("")]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct DeveloperOptionsScreen_Previews: PreviewProvider {
|
||||
|
||||
Reference in New Issue
Block a user