Logging overhaul
This commit is contained in:
@@ -196,7 +196,7 @@ struct LiveActivityDebugView: View {
|
||||
}
|
||||
|
||||
isTestRunning = true
|
||||
appendDebugOutput("🧪 Starting Live Activity test...")
|
||||
appendDebugOutput("Starting Live Activity test...")
|
||||
|
||||
Task {
|
||||
defer {
|
||||
|
||||
@@ -317,7 +317,6 @@ struct ProblemsList: View {
|
||||
}
|
||||
|
||||
Button {
|
||||
// Use a spring animation for more natural movement
|
||||
withAnimation(.spring(response: 0.5, dampingFraction: 0.8, blendDuration: 0.1))
|
||||
{
|
||||
let updatedProblem = problem.updated(isActive: !problem.isActive)
|
||||
|
||||
@@ -84,6 +84,8 @@ struct DataManagementSection: View {
|
||||
@State private var isDeletingImages = false
|
||||
@State private var showingDeleteImagesAlert = false
|
||||
|
||||
private static let logTag = "DataManagementSection"
|
||||
|
||||
var body: some View {
|
||||
Section("Data Management") {
|
||||
// Export Data
|
||||
@@ -217,13 +219,14 @@ struct DataManagementSection: View {
|
||||
try fileManager.removeItem(at: imageFile)
|
||||
deletedCount += 1
|
||||
} catch {
|
||||
print("Failed to delete image: \(imageFile.lastPathComponent)")
|
||||
AppLogger.error(
|
||||
"Failed to delete image: \(imageFile.lastPathComponent)", tag: Self.logTag)
|
||||
}
|
||||
}
|
||||
|
||||
print("Deleted \(deletedCount) image files")
|
||||
AppLogger.info("Deleted \(deletedCount) image files", tag: Self.logTag)
|
||||
} catch {
|
||||
print("Failed to access images directory: \(error)")
|
||||
AppLogger.error("Failed to access images directory: \(error)", tag: Self.logTag)
|
||||
}
|
||||
|
||||
// Delete all images from backup directory
|
||||
@@ -235,7 +238,7 @@ struct DataManagementSection: View {
|
||||
try? fileManager.removeItem(at: backupFile)
|
||||
}
|
||||
} catch {
|
||||
print("Failed to access backup directory: \(error)")
|
||||
AppLogger.error("Failed to access backup directory: \(error)", tag: Self.logTag)
|
||||
}
|
||||
|
||||
// Clear image paths from all problems
|
||||
@@ -260,20 +263,6 @@ struct AppInfoSection: View {
|
||||
|
||||
var body: some View {
|
||||
Section("App Information") {
|
||||
HStack {
|
||||
Image("AppLogo")
|
||||
.resizable()
|
||||
.frame(width: 24, height: 24)
|
||||
VStack(alignment: .leading) {
|
||||
Text("Ascently")
|
||||
.font(.headline)
|
||||
Text("Track your climbing progress")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Image(systemName: "info.circle")
|
||||
.foregroundColor(.blue)
|
||||
@@ -292,11 +281,13 @@ struct ExportDataView: View {
|
||||
@State private var tempFileURL: URL?
|
||||
@State private var isCreatingFile = true
|
||||
|
||||
private static let logTag = "ExportDataView"
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
VStack(spacing: 30) {
|
||||
if isCreatingFile {
|
||||
// Loading state - more prominent
|
||||
// Loading state
|
||||
VStack(spacing: 20) {
|
||||
ProgressView()
|
||||
.scaleEffect(1.5)
|
||||
@@ -380,6 +371,7 @@ struct ExportDataView: View {
|
||||
}
|
||||
|
||||
private func createTempFile() {
|
||||
let logTag = Self.logTag // Capture before entering background queue
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
do {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
@@ -394,7 +386,9 @@ struct ExportDataView: View {
|
||||
for: .documentDirectory, in: .userDomainMask
|
||||
).first
|
||||
else {
|
||||
print("Could not access Documents directory")
|
||||
Task { @MainActor in
|
||||
AppLogger.error("Could not access Documents directory", tag: logTag)
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.isCreatingFile = false
|
||||
}
|
||||
@@ -410,7 +404,9 @@ struct ExportDataView: View {
|
||||
self.isCreatingFile = false
|
||||
}
|
||||
} catch {
|
||||
print("Failed to create export file: \(error)")
|
||||
Task { @MainActor in
|
||||
AppLogger.error("Failed to create export file: \(error)", tag: logTag)
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.isCreatingFile = false
|
||||
}
|
||||
@@ -420,10 +416,12 @@ struct ExportDataView: View {
|
||||
|
||||
private func cleanupTempFile() {
|
||||
if let fileURL = tempFileURL {
|
||||
let logTag = Self.logTag // Capture before entering async closure
|
||||
// Clean up after a delay to ensure sharing is complete
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
|
||||
try? FileManager.default.removeItem(at: fileURL)
|
||||
print("Cleaned up export file: \(fileURL.lastPathComponent)")
|
||||
AppLogger.debug(
|
||||
"Cleaned up export file: \(fileURL.lastPathComponent)", tag: logTag)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,6 +433,8 @@ struct SyncSection: View {
|
||||
@State private var showingSyncSettings = false
|
||||
@State private var showingDisconnectAlert = false
|
||||
|
||||
private static let logTag = "SyncSection"
|
||||
|
||||
var body: some View {
|
||||
Section("Sync") {
|
||||
// Sync Status
|
||||
@@ -579,11 +579,14 @@ struct SyncSection: View {
|
||||
}
|
||||
|
||||
private func performSync() {
|
||||
let logTag = Self.logTag // Capture before entering async context
|
||||
Task {
|
||||
do {
|
||||
try await syncService.syncWithServer(dataManager: dataManager)
|
||||
} catch {
|
||||
print("Sync failed: \(error)")
|
||||
await MainActor.run {
|
||||
AppLogger.error("Sync failed: \(error)", tag: logTag)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user