⚠️ Use OSLogStore instead.
Opens a /usr/bin/log stream
Process
and parses data sent to the Pipe
via its readabilityHandler
with Regex
.
Instantiate a LogStream
's:
init(subsystem: String, delegate: LogStreamDelegateProtocol, historySize: Int? = nil)
where subsystem
is e.g. "com.apple.TimeMachine", LogStreamDelegateProtocol
is:
func newLogEntry(entry: LogEntry, history: History<LogEntry>)
and History
is a FIFO queue of the specified length, or nil
for infinite length.
The previous logs are returned since the event indicated by the current log entry might desire data from other recent entries. E.g. when a Time Machine backup completes, that event does not contain the volume name, but it will be in a recent log entry.
I believe any apps built with this will require admin access to read /usr/bin/log
.
New XCode apps include the App Sandbox capability which must be removed – under the target's "signing and capabilities".
- Logging in Swift article on steipete.com suggests using
OSLogStore
but I had already written this much before I saw that. - StackOverflow user Vadian, in Event notifications in macOS, suggests using
DistributedNotificationCenter
for Time Machine (my use case). - Filtering the logs could be implemented via predicates, see: log: a primer on predicates on the great The Eclectic Light Company website.
- Parsing could be much lazier.