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:
Stefan Ceriu
2023-08-30 15:35:49 +03:00
committed by GitHub
parent 3c3e31f9e4
commit 3258d3a85d
4 changed files with 109 additions and 44 deletions
@@ -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 {