Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Add hacky log exporting for TestFlight
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 24, 2024
1 parent 350098a commit 872fdaa
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Aware/macOS/MenuBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,36 @@ private func findStatusBarItem() -> NSStatusItem? {
struct MenuBarContentView: View {
var body: some View {
SettingsLink()
// FIXME: Remove before next release
Button("Export Logs") {
Task<Void, Never>(priority: .background) {
exportLogs()
}
}.keyboardShortcut("e")
Divider()
Button("Quit") {
NSApplication.shared.terminate(nil)
}.keyboardShortcut("q")
}

func exportLogs() {
let store = try! OSLogStore(scope: .currentProcessIdentifier)
let predicate = NSPredicate(format: "subsystem == 'com.awaremac.Aware'")
let date = Date.now.addingTimeInterval(-3600)
let position = store.position(date: date)
let data = try! store
.getEntries(at: position, matching: predicate)
.compactMap { $0 as? OSLogEntryLog }
.map { "[\($0.date.formatted(date: .omitted, time: .standard))] [\($0.category)] \($0.composedMessage)\n" }
.joined()
.data(using: .utf8)!
let fileURL = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)
.first!
.appendingPathComponent("Logs", isDirectory: true)
.appendingPathComponent("Aware.log")
try! data.write(to: fileURL)
NSWorkspace.shared.activateFileViewerSelecting([fileURL])
}
}

#endif

0 comments on commit 872fdaa

Please sign in to comment.