Skip to content

Commit

Permalink
Add function to retrieve log entries in File provider Logger extension
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Nov 1, 2023
1 parent b58a721 commit e717e5d
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,24 @@ extension Logger {
static let localFileOps = Logger(subsystem: subsystem, category: "localfileoperations")
static let ncFilesDatabase = Logger(subsystem: subsystem, category: "nextcloudfilesdatabase")
static let materialisedFileHandling = Logger(subsystem: subsystem, category: "materialisedfilehandling")
static let logger = Logger(subsystem: subsystem, category: "logger")

@available(macOSApplicationExtension 12.0, *)
static func logEntries(interval: TimeInterval = -3600) -> Array<String>? {
do {
let logStore = try OSLogStore(scope: .currentProcessIdentifier)
let timeDate = Date().addingTimeInterval(interval)
let logPosition = logStore.position(date: timeDate)
let entries = try logStore.getEntries(at: logPosition)

return entries
.compactMap { $0 as? OSLogEntryLog }
.filter { $0.subsystem == Logger.subsystem }
.map { $0.composedMessage }

} catch let error {
Logger.logger.error("Could not acquire os log store: \(error)");
return nil
}
}
}

0 comments on commit e717e5d

Please sign in to comment.