I'm trying to use the new OSLogStore
object to retrieve created logs. It's very common to see the scope initialiser used like OSLogStore(scope: .currentProcessIdentifier)
. This works fine as long as I don't kill the app, but when I do, I cannot retrieve logs from a previous run. At least not on my simulator.
I would like to be able to persist the logs to a file and manually manage the file (if needed). So I attempted to use the OSLogStore(url:)
initialiser, but that doesn't seem to work.
let url = FileManager.default.temporaryDirectory.appendingPathComponent("logs")
try OSLogStore(url: url)
// Error Domain=OSLogErrorDomain Code=1
// "The specified URL did not refer to a valid log archive"
// UserInfo={
// _OSLogErrorPOSIXErrno=2,
// NSLocalizedDescription=The specified URL did not refer to a valid log archive,
// _OSLogErrorInternalCode=3
// }
That made me think that maybe this throws an error, as the file doesn't exist, so I also tried to write an empty file to the location and change path extensions (to .logs
, .log
and .logarchive
), but so far without luck.
Is there anyone who knows how I can manually tell the OSLog
framework at which location to store the logs?