Before the era of system/network extensions, we could specify stdout/stderr log locations for our daemons which were launched by launchd
. Is it possible to do the same with system extensions?
Is it possible to do the same with system extensions?
While i'm sure it may be technically still possible to pipe stdout
and stderr
to a file or other location, I find it much easier to stream logs from the Network System Extension with the os_log
API. Something like so usually works for me:
// Objective-C
#import <os/log.h>
@property os_log_t log;
...
_log = os_log_create("com.example.apple-samplecode.MyProject.MySystemExtension", "provider");
...
os_log(self._log, "provider will start");
...
os_log(self._log, "Failed to apply filter settings: %{public}@", error.localizedDescription);
// Swift
let log = OSLog(subsystem: "com.example.apple-samplecode.MyProject.MySystemExtension", category: "provider")
...
os_log(.debug, log: self.log, "provider will start")
if let error = coreError as NSError? {
os_log(.debug, log: self.log, "provider did not start, core failed, error: %{public}@ / %zd", error.domain, error.code)
}
And then for viewing these logs in the Terminal while your System Extension is running, you can run the commands:
$ log stream --level debug --predicate 'subsystem == "com.example.apple-samplecode.MyProject.MySystemExtension"'
... Lots of output ...
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com