From d0d383f5cef1d0de4cb41c927d6166b7a594a44f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 28 Jun 2024 18:21:54 -0700 Subject: [PATCH 1/5] Colorful logs --- Meshtastic/Extensions/Logger.swift | 12 ++++++++++++ Meshtastic/Helpers/BLEManager.swift | 2 +- Meshtastic/Views/Settings/AppLog.swift | 8 +++++--- Meshtastic/Views/Settings/Logs/AppLogFilter.swift | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Meshtastic/Extensions/Logger.swift b/Meshtastic/Extensions/Logger.swift index 9dc12a881..95817ea40 100644 --- a/Meshtastic/Extensions/Logger.swift +++ b/Meshtastic/Extensions/Logger.swift @@ -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 + } + } } diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index ecac0aa5d..e9fce9166 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -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 diff --git a/Meshtastic/Views/Settings/AppLog.swift b/Meshtastic/Views/Settings/AppLog.swift index a3dcd59d7..975a302eb 100644 --- a/Meshtastic/Views/Settings/AppLog.swift +++ b/Meshtastic/Views/Settings/AppLog.swift @@ -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) diff --git a/Meshtastic/Views/Settings/Logs/AppLogFilter.swift b/Meshtastic/Views/Settings/Logs/AppLogFilter.swift index fa3a41e69..5dfa699a2 100644 --- a/Meshtastic/Views/Settings/Logs/AppLogFilter.swift +++ b/Meshtastic/Views/Settings/Logs/AppLogFilter.swift @@ -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! From c7f7e14e6632a02070a73f9d41e616a09db9b522 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 28 Jun 2024 18:25:41 -0700 Subject: [PATCH 2/5] Log details level colors --- .../Views/Settings/Logs/LogDetail.swift | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Meshtastic/Views/Settings/Logs/LogDetail.swift b/Meshtastic/Views/Settings/Logs/LogDetail.swift index c05d4b831..8006127e3 100644 --- a/Meshtastic/Views/Settings/Logs/LogDetail.swift +++ b/Meshtastic/Views/Settings/Logs/LogDetail.swift @@ -81,36 +81,38 @@ struct LogDetail: View { } .padding(.bottom, 5) .listRowSeparator(.visible) - /// Category + /// Level Label { - Text("log.category".localized + ":") + Text("log.level".localized + ":") .font(idiom == .phone ? .caption : .title) .frame(width: idiom == .phone ? 115 : 190, alignment: .trailing) - Text(log.category) + Text(log.level.description) .font(idiom == .phone ? .caption : .title) + .foregroundStyle(log.level.color) } icon: { - Image(systemName: "square.grid.2x2") + Image(systemName: "stairs") .symbolRenderingMode(.hierarchical) .font(idiom == .phone ? .caption : .title) .frame(width: 35) } .padding(.bottom, 5) .listRowSeparator(.visible) - /// Level + /// Category Label { - Text("log.level".localized + ":") + Text("log.category".localized + ":") .font(idiom == .phone ? .caption : .title) .frame(width: idiom == .phone ? 115 : 190, alignment: .trailing) - Text(log.level.description) + Text(log.category) .font(idiom == .phone ? .caption : .title) } icon: { - Image(systemName: "stairs") + Image(systemName: "square.grid.2x2") .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") From 9f1b3975f8a59b51975b1c509e72c4ec2e4f891c Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 28 Jun 2024 19:30:12 -0700 Subject: [PATCH 3/5] Use indigo for debug color, clean up filters --- Meshtastic.xcodeproj/project.pbxproj | 4 +++ Meshtastic/Extensions/Logger.swift | 26 -------------- Meshtastic/Extensions/OSLogEntryLog.swift | 35 +++++++++++++++++++ .../Helpers/Map/OfflineTileManager.swift | 2 +- Meshtastic/Persistence/UpdateCoreData.swift | 2 +- .../Views/Settings/Logs/AppLogFilter.swift | 2 +- 6 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 Meshtastic/Extensions/OSLogEntryLog.swift diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 6e724c462..3ff8481e0 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -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 */; }; @@ -397,6 +398,7 @@ DDD5BB0F2C285FB3007E03CA /* AppLogFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLogFilter.swift; sourceTree = ""; }; DDD5BB142C28680D007E03CA /* MeshtasticDataModelV 38.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 38.xcdatamodel"; sourceTree = ""; }; DDD5BB152C28B1E4007E03CA /* AppData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppData.swift; sourceTree = ""; }; + DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLogEntryLog.swift; sourceTree = ""; }; DDD6EEAE29BC024700383354 /* Firmware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Firmware.swift; sourceTree = ""; }; DDD94A4F2845C8F5004A87A0 /* DateTimeText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTimeText.swift; sourceTree = ""; }; DDD9E4E3284B208E003777C5 /* UserEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserEntityExtension.swift; sourceTree = ""; }; @@ -903,6 +905,7 @@ DDFFA7462B3A7F3C004730DB /* Bundle.swift */, DDF45C362BC46A5A005ED5F2 /* TimeZone.swift */, DDD5BB0C2C285F00007E03CA /* Logger.swift */, + DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */, ); path = Extensions; sourceTree = ""; @@ -1095,6 +1098,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 */, diff --git a/Meshtastic/Extensions/Logger.swift b/Meshtastic/Extensions/Logger.swift index 95817ea40..402c0c1b8 100644 --- a/Meshtastic/Extensions/Logger.swift +++ b/Meshtastic/Extensions/Logger.swift @@ -6,7 +6,6 @@ // import OSLog -import SwiftUI extension Logger { @@ -59,28 +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" - } - } - 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 - } - } -} diff --git a/Meshtastic/Extensions/OSLogEntryLog.swift b/Meshtastic/Extensions/OSLogEntryLog.swift new file mode 100644 index 000000000..9d42b70ce --- /dev/null +++ b/Meshtastic/Extensions/OSLogEntryLog.swift @@ -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 + } + } +} diff --git a/Meshtastic/Helpers/Map/OfflineTileManager.swift b/Meshtastic/Helpers/Map/OfflineTileManager.swift index dceb09cc8..66afa93c3 100644 --- a/Meshtastic/Helpers/Map/OfflineTileManager.swift +++ b/Meshtastic/Helpers/Map/OfflineTileManager.swift @@ -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() } diff --git a/Meshtastic/Persistence/UpdateCoreData.swift b/Meshtastic/Persistence/UpdateCoreData.swift index e7f9567c6..4073eb903 100644 --- a/Meshtastic/Persistence/UpdateCoreData.swift +++ b/Meshtastic/Persistence/UpdateCoreData.swift @@ -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 diff --git a/Meshtastic/Views/Settings/Logs/AppLogFilter.swift b/Meshtastic/Views/Settings/Logs/AppLogFilter.swift index 5dfa699a2..46d6f8380 100644 --- a/Meshtastic/Views/Settings/Logs/AppLogFilter.swift +++ b/Meshtastic/Views/Settings/Logs/AppLogFilter.swift @@ -81,7 +81,7 @@ enum LogLevels: Int, CaseIterable, Identifiable { var color: Color { switch self { case .debug: - return .blue + return .indigo case .info: return .green case .notice: From a8399f61484cb41a7b883205a554f3ef97aa189d Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 28 Jun 2024 19:41:17 -0700 Subject: [PATCH 4/5] Swiftlint updates --- Meshtastic/Extensions/CoreData/MQTTConfigEntityExtension.swift | 2 +- .../Extensions/CoreData/RangeTestConfigEntityExtension.swift | 2 +- .../Extensions/CoreData/SerialConfigEntityExtension.swift | 2 +- .../Extensions/CoreData/StoreForwardConfigEntityExtension.swift | 2 +- Meshtastic/Views/Settings/AppData.swift | 1 - 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Meshtastic/Extensions/CoreData/MQTTConfigEntityExtension.swift b/Meshtastic/Extensions/CoreData/MQTTConfigEntityExtension.swift index ca01ba912..29b1d064c 100644 --- a/Meshtastic/Extensions/CoreData/MQTTConfigEntityExtension.swift +++ b/Meshtastic/Extensions/CoreData/MQTTConfigEntityExtension.swift @@ -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 diff --git a/Meshtastic/Extensions/CoreData/RangeTestConfigEntityExtension.swift b/Meshtastic/Extensions/CoreData/RangeTestConfigEntityExtension.swift index d85a6ab81..20aa1713f 100644 --- a/Meshtastic/Extensions/CoreData/RangeTestConfigEntityExtension.swift +++ b/Meshtastic/Extensions/CoreData/RangeTestConfigEntityExtension.swift @@ -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 diff --git a/Meshtastic/Extensions/CoreData/SerialConfigEntityExtension.swift b/Meshtastic/Extensions/CoreData/SerialConfigEntityExtension.swift index da48dde2e..49400a942 100644 --- a/Meshtastic/Extensions/CoreData/SerialConfigEntityExtension.swift +++ b/Meshtastic/Extensions/CoreData/SerialConfigEntityExtension.swift @@ -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 diff --git a/Meshtastic/Extensions/CoreData/StoreForwardConfigEntityExtension.swift b/Meshtastic/Extensions/CoreData/StoreForwardConfigEntityExtension.swift index c44de4f70..886a79d5e 100644 --- a/Meshtastic/Extensions/CoreData/StoreForwardConfigEntityExtension.swift +++ b/Meshtastic/Extensions/CoreData/StoreForwardConfigEntityExtension.swift @@ -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 diff --git a/Meshtastic/Views/Settings/AppData.swift b/Meshtastic/Views/Settings/AppData.swift index dee18d9fc..1d38844de 100644 --- a/Meshtastic/Views/Settings/AppData.swift +++ b/Meshtastic/Views/Settings/AppData.swift @@ -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) From 509037c1028bc1958a75134109e601c2b441df8f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 28 Jun 2024 22:07:52 -0700 Subject: [PATCH 5/5] Remove extra space --- Meshtastic.xcodeproj/project.pbxproj | 4 ++-- Meshtastic/Extensions/OSLogEntryLog.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 3ff8481e0..28a362982 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -887,6 +887,7 @@ isa = PBXGroup; children = ( DD007BB12AA59B9A00F5FA12 /* CoreData */, + DDFFA7462B3A7F3C004730DB /* Bundle.swift */, DDDB444529F8A96500EE2349 /* Character.swift */, DDDB444929F8AA3A00EE2349 /* CLLocationCoordinate2D.swift */, DDDB444B29F8AAA600EE2349 /* Color.swift */, @@ -902,10 +903,9 @@ DDB75A0E2A05920E006ED576 /* FileManager.swift */, DDB75A102A059258006ED576 /* Url.swift */, DD1933772B084F4200771CD5 /* Measurement.swift */, - DDFFA7462B3A7F3C004730DB /* Bundle.swift */, + DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */, DDF45C362BC46A5A005ED5F2 /* TimeZone.swift */, DDD5BB0C2C285F00007E03CA /* Logger.swift */, - DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */, ); path = Extensions; sourceTree = ""; diff --git a/Meshtastic/Extensions/OSLogEntryLog.swift b/Meshtastic/Extensions/OSLogEntryLog.swift index 9d42b70ce..fe2dc2cfc 100644 --- a/Meshtastic/Extensions/OSLogEntryLog.swift +++ b/Meshtastic/Extensions/OSLogEntryLog.swift @@ -17,7 +17,7 @@ extension OSLogEntryLog.Level { case .info: "ℹī¸ Info" case .notice: "⚠ī¸ Notice" case .error: "🚨 Error" - case .fault: "đŸ’Ĩ Fault" + case .fault: "đŸ’Ĩ Fault" @unknown default: "default" } }