Skip to content

Instantly share code, notes, and snippets.

@erikng
Forked from steipete/OSLogTest.swift
Created February 15, 2021 22:26
Show Gist options
  • Select an option

  • Save erikng/4b47aad70c6a07a72d5a641251971c3f to your computer and use it in GitHub Desktop.

Select an option

Save erikng/4b47aad70c6a07a72d5a641251971c3f to your computer and use it in GitHub Desktop.

Revisions

  1. @steipete steipete created this gist Aug 24, 2020.
    19 changes: 19 additions & 0 deletions OSLogTest.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    let subsystem = "com.steipete.LoggingTest"

    func getLogEntries() throws -> [OSLogEntryLog] {
    // FB8269189: OSLogStore does not work iOS.
    let logStore = try OSLogStore(scope: .currentProcessIdentifier)
    let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600))

    #if os(macOS)
    let allEntries = try logStore.getEntries(at: oneHourAgo)
    #else
    // FB8518476: The Swift shims for for the entries enumerator are missing.
    let allEntries = try Array(logStore.__entriesEnumerator(position: oneHourAgo, predicate: nil))
    #endif

    // FB8518539: Using NSPredicate to filter the subsystem doesn't seem to work.
    return allEntries
    .compactMap { $0 as? OSLogEntryLog }
    .filter { $0.subsystem == subsystem }
    }