Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log level colors #737

Merged
merged 5 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Meshtastic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -397,6 +398,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>"; };
Expand Down Expand Up @@ -885,6 +887,7 @@
isa = PBXGroup;
children = (
DD007BB12AA59B9A00F5FA12 /* CoreData */,
DDFFA7462B3A7F3C004730DB /* Bundle.swift */,
DDDB444529F8A96500EE2349 /* Character.swift */,
DDDB444929F8AA3A00EE2349 /* CLLocationCoordinate2D.swift */,
DDDB444B29F8AAA600EE2349 /* Color.swift */,
Expand All @@ -900,7 +903,7 @@
DDB75A0E2A05920E006ED576 /* FileManager.swift */,
DDB75A102A059258006ED576 /* Url.swift */,
DD1933772B084F4200771CD5 /* Measurement.swift */,
DDFFA7462B3A7F3C004730DB /* Bundle.swift */,
DDD5BB172C2F9C36007E03CA /* OSLogEntryLog.swift */,
DDF45C362BC46A5A005ED5F2 /* TimeZone.swift */,
DDD5BB0C2C285F00007E03CA /* Logger.swift */,
);
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions Meshtastic/Extensions/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
35 changes: 35 additions & 0 deletions Meshtastic/Extensions/OSLogEntryLog.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 1 addition & 1 deletion Meshtastic/Helpers/BLEManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Meshtastic/Helpers/Map/OfflineTileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion Meshtastic/Persistence/UpdateCoreData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Meshtastic/Views/Settings/AppData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions Meshtastic/Views/Settings/AppLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions Meshtastic/Views/Settings/Logs/AppLogFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!
Expand Down
19 changes: 11 additions & 8 deletions Meshtastic/Views/Settings/Logs/LogDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ":")
Expand All @@ -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")
Expand Down