43 lines
1.3 KiB
Swift
43 lines
1.3 KiB
Swift
|
//
|
||
|
// Logging.swift
|
||
|
// Tusker
|
||
|
//
|
||
|
// Created by Shadowfacts on 10/10/22.
|
||
|
// Copyright © 2022 Shadowfacts. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
import OSLog
|
||
|
|
||
|
struct Logging {
|
||
|
private init() {}
|
||
|
|
||
|
static let general = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "General")
|
||
|
|
||
|
static func getLogData() -> Data? {
|
||
|
do {
|
||
|
let store = try OSLogStore(scope: .currentProcessIdentifier)
|
||
|
// past hour
|
||
|
let position = store.position(date: Date().addingTimeInterval(-60 * 60))
|
||
|
let entries = try store.getEntries(at: position, matching: NSPredicate(format: "subsystem = %@", Bundle.main.bundleIdentifier!))
|
||
|
var data = Data()
|
||
|
for entry in entries {
|
||
|
guard let entry = entry as? OSLogEntryLog else {
|
||
|
continue
|
||
|
}
|
||
|
data.append(contentsOf: entry.date.formatted(.iso8601).utf8)
|
||
|
data.append(32) // ' '
|
||
|
data.append(91) // '['
|
||
|
data.append(contentsOf: entry.category.utf8)
|
||
|
data.append(93) // ']'
|
||
|
data.append(32) // ' '
|
||
|
data.append(contentsOf: entry.composedMessage.utf8)
|
||
|
data.append(10) // '\n'
|
||
|
}
|
||
|
return data
|
||
|
} catch {
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
}
|