Colorful logs

This commit is contained in:
Garth Vander Houwen 2024-06-28 18:21:54 -07:00
parent 7aa9bbf497
commit d0d383f5ce
4 changed files with 33 additions and 4 deletions

View file

@ -6,6 +6,7 @@
//
import OSLog
import SwiftUI
extension Logger {
@ -71,4 +72,15 @@ extension OSLogEntryLog.Level {
@unknown default: "default"
}
}
var color: Color {
switch self {
case .undefined: .green
case .debug: .blue
case .info: .green
case .notice: .orange
case .error: .red
case .fault: .red
@unknown default: .green
}
}
}

View file

@ -848,7 +848,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
invalidVersion = false
lastConnectionError = ""
isSubscribed = true
Logger.mesh.info("[BLE] 🤜 Want Config Complete. ID:\(decodedInfo.configCompleteID)")
Logger.mesh.info("🤜 [BLE] Want Config Complete. ID:\(decodedInfo.configCompleteID)")
peripherals.removeAll(where: { $0.peripheral.state == CBPeripheralState.disconnected })
// Config conplete returns so we don't read the characteristic again

View file

@ -9,7 +9,7 @@ import SwiftUI
import OSLog
/// Needed for TableColumnForEach
@available(iOS 17.4, *)
@available(iOS 17.4, macOS 14.4, *)
struct AppLog: View {
@State private var logs: [OSLogEntryLog] = []
@ -40,15 +40,17 @@ struct AppLog: View {
Text(value.date.formatted(dateFormatStyle))
}
.width(min: 125, max: 150)
TableColumn("log.category", value: \.category)
.width(min: 125, max: 150)
TableColumn("log.level") { value in
Text(value.level.description)
.foregroundStyle(value.level.color)
}
.width(min: 75, max: 100)
TableColumn("log.category", value: \.category)
.width(min: 125, max: 150)
}
TableColumn("log.message", value: \.composedMessage) { value in
Text(value.composedMessage)
.foregroundStyle(value.level.color)
.font(idiom == .phone ? .caption : .body)
}
.width(ideal: 200, max: .infinity)

View file

@ -78,6 +78,20 @@ enum LogLevels: Int, CaseIterable, Identifiable {
return "💥 Fault"
}
}
var color: Color {
switch self {
case .debug:
return .blue
case .info:
return .green
case .notice:
return .orange
case .error:
return .red
case .fault:
return .red
}
}
}
struct AppLogFilter: View {
@ -107,6 +121,7 @@ struct AppLogFilter: View {
VStack {
List(LogLevels.allCases, selection: $levels) { level in
Text(level.description)
.foregroundStyle(level.color)
}
.listStyle(.plain)
.environment(\.editMode, $editMode) /// bind it here!