Merge pull request #737 from meshtastic/log_level_colors

Log level colors
This commit is contained in:
Garth Vander Houwen 2024-06-28 22:32:40 -07:00 committed by GitHub
commit 8ab0139af4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 85 additions and 41 deletions

View file

@ -152,6 +152,7 @@
DDD5BB092C285DDC007E03CA /* AppLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD5BB082C285DDC007E03CA /* AppLog.swift */; };
DDD5BB0B2C285E45007E03CA /* LogDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD5BB0A2C285E45007E03CA /* LogDetail.swift */; };
DDD5BB102C285FB3007E03CA /* AppLogFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD5BB0F2C285FB3007E03CA /* AppLogFilter.swift */; };
DDD5BB182C2F9C36007E03CA /* OSLogEntryLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */; };
DDD6EEAF29BC024700383354 /* Firmware.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD6EEAE29BC024700383354 /* Firmware.swift */; };
DDD94A502845C8F5004A87A0 /* DateTimeText.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD94A4F2845C8F5004A87A0 /* DateTimeText.swift */; };
DDD9E4E4284B208E003777C5 /* UserEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD9E4E3284B208E003777C5 /* UserEntityExtension.swift */; };
@ -393,6 +394,7 @@
DDD5BB0F2C285FB3007E03CA /* AppLogFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLogFilter.swift; sourceTree = "<group>"; };
DDD5BB142C28680D007E03CA /* MeshtasticDataModelV 38.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 38.xcdatamodel"; sourceTree = "<group>"; };
DDD5BB152C28B1E4007E03CA /* AppData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppData.swift; sourceTree = "<group>"; };
DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLogEntryLog.swift; sourceTree = "<group>"; };
DDD6EEAE29BC024700383354 /* Firmware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Firmware.swift; sourceTree = "<group>"; };
DDD94A4F2845C8F5004A87A0 /* DateTimeText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTimeText.swift; sourceTree = "<group>"; };
DDD9E4E3284B208E003777C5 /* UserEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserEntityExtension.swift; sourceTree = "<group>"; };
@ -877,6 +879,7 @@
isa = PBXGroup;
children = (
DD007BB12AA59B9A00F5FA12 /* CoreData */,
DDFFA7462B3A7F3C004730DB /* Bundle.swift */,
DDDB444529F8A96500EE2349 /* Character.swift */,
DDDB444929F8AA3A00EE2349 /* CLLocationCoordinate2D.swift */,
DDDB444B29F8AAA600EE2349 /* Color.swift */,
@ -892,7 +895,7 @@
DDB75A0E2A05920E006ED576 /* FileManager.swift */,
DDB75A102A059258006ED576 /* Url.swift */,
DD1933772B084F4200771CD5 /* Measurement.swift */,
DDFFA7462B3A7F3C004730DB /* Bundle.swift */,
DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */,
DDF45C362BC46A5A005ED5F2 /* TimeZone.swift */,
DDD5BB0C2C285F00007E03CA /* Logger.swift */,
);
@ -1087,6 +1090,7 @@
D93069082B81DF040066FBC8 /* SaveConfigButton.swift in Sources */,
DD5E523F298F5A9E00D21B61 /* AirQualityIndex.swift in Sources */,
DD964FBF296E76EF007C176F /* WaypointFormMapKit.swift in Sources */,
DDD5BB182C2F9C36007E03CA /* OSLogEntryLog.swift in Sources */,
DD3501892852FC3B000FC853 /* Settings.swift in Sources */,
DDDC22382BA92344002C44F1 /* MeshMapContent.swift in Sources */,
DDDB443629F6287000EE2349 /* MapButtons.swift in Sources */,

View file

@ -20,7 +20,7 @@ extension MQTTConfigEntity {
self.mapPositionPrecision = Int32(config.mapReportSettings.positionPrecision)
self.mapPublishIntervalSecs = Int32(config.mapReportSettings.publishIntervalSecs)
}
func update(with config: ModuleConfig.MQTTConfig) {
enabled = config.enabled
proxyToClientEnabled = config.proxyToClientEnabled

View file

@ -11,7 +11,7 @@ extension RangeTestConfigEntity {
self.enabled = config.enabled
self.save = config.save
}
func update(with config: ModuleConfig.RangeTestConfig) {
sender = Int32(config.sender)
enabled = config.enabled

View file

@ -15,7 +15,7 @@ extension SerialConfigEntity {
self.timeout = Int32(config.timeout)
self.mode = Int32(config.mode.rawValue)
}
func update(with config: ModuleConfig.SerialConfig) {
enabled = config.enabled
echo = config.echo

View file

@ -13,7 +13,7 @@ extension StoreForwardConfigEntity {
self.historyReturnMax = Int32(config.historyReturnMax)
self.historyReturnWindow = Int32(config.historyReturnWindow)
}
func update(with config: ModuleConfig.StoreForwardConfig) {
enabled = config.enabled
heartbeat = config.heartbeat

View file

@ -58,17 +58,3 @@ extension Logger {
return logs
}
}
extension OSLogEntryLog.Level {
var description: String {
switch self {
case .undefined: "undefined"
case .debug: "🪲 Debug"
case .info: " Info"
case .notice: "⚠️ Notice"
case .error: "🚨 Error"
case .fault: "💥 Fault"
@unknown default: "default"
}
}
}

View file

@ -0,0 +1,35 @@
//
// OSLogEntryLog.swift
// Meshtastic
//
// Copyright(c) Garth Vander Houwen 6/28/24.
//
import OSLog
import SwiftUI
/// Extensions to allow rendering of the emoji string and log leve coloring in the grid of OSLogEntryLog items
extension OSLogEntryLog.Level {
var description: String {
switch self {
case .undefined: "undefined"
case .debug: "🪲 Debug"
case .info: " Info"
case .notice: "⚠️ Notice"
case .error: "🚨 Error"
case .fault: "💥 Fault"
@unknown default: "default"
}
}
var color: Color {
switch self {
case .undefined: .green
case .debug: .indigo
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

@ -21,7 +21,7 @@ class OfflineTileManager: ObservableObject {
}
init() {
Logger.services.debug("Documents Directory = \(self.documentsDirectory.absoluteString, privacy: .public)")
Logger.services.info("🗂️ Documents Directory = \(self.documentsDirectory.absoluteString, privacy: .public)")
createDirectoriesIfNecessary()
}

View file

@ -353,7 +353,7 @@ func upsertPositionPacket (packet: MeshPacket, context: NSManagedObjectContext)
do {
try context.save()
Logger.data.info("💾 Updated Node Position Coordinates from Position App Packet For: \(fetchedNode[0].num.toHex(), privacy: .public)")
Logger.data.info("💾 [Position] Saved from Position App Packet For: \(fetchedNode[0].num.toHex(), privacy: .public)")
} catch {
context.rollback()
let nsError = error as NSError

View file

@ -59,7 +59,6 @@ struct AppData: View {
bleManager.disconnectPeripheral(reconnect: false)
let container = NSPersistentContainer(name: "Meshtastic")
do {
clearCoreDataDatabase(context: context, includeRoutes: true)
try container.restorePersistentStore(from: file.absoluteURL)
let request = MyInfoEntity.fetchRequest()
try context.fetch(request)

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 .indigo
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!

View file

@ -81,6 +81,22 @@ struct LogDetail: View {
}
.padding(.bottom, 5)
.listRowSeparator(.visible)
/// Level
Label {
Text("log.level".localized + ":")
.font(idiom == .phone ? .caption : .title)
.frame(width: idiom == .phone ? 115 : 190, alignment: .trailing)
Text(log.level.description)
.font(idiom == .phone ? .caption : .title)
.foregroundStyle(log.level.color)
} icon: {
Image(systemName: "stairs")
.symbolRenderingMode(.hierarchical)
.font(idiom == .phone ? .caption : .title)
.frame(width: 35)
}
.padding(.bottom, 5)
.listRowSeparator(.visible)
/// Category
Label {
Text("log.category".localized + ":")
@ -96,21 +112,7 @@ struct LogDetail: View {
}
.padding(.bottom, 5)
.listRowSeparator(.visible)
/// Level
Label {
Text("log.level".localized + ":")
.font(idiom == .phone ? .caption : .title)
.frame(width: idiom == .phone ? 115 : 190, alignment: .trailing)
Text(log.level.description)
.font(idiom == .phone ? .caption : .title)
} icon: {
Image(systemName: "stairs")
.symbolRenderingMode(.hierarchical)
.font(idiom == .phone ? .caption : .title)
.frame(width: 35)
}
.padding(.bottom, 5)
.listRowSeparator(.visible)
/// message
Label {
Text("log.message".localized + ":")
@ -119,6 +121,7 @@ struct LogDetail: View {
Text(log.composedMessage)
.textSelection(.enabled)
.font(idiom == .phone ? .body : .title)
.foregroundStyle(log.level.color)
.padding(.bottom, 5)
} icon: {
Image(systemName: "text.bubble")