Currently I have a setup which duplicates the stderr STDERR_FILENO pipe into a separate one.
Then by setting up a readabilityHandler (on the new Pipe) I can capture the logged data and either store it inside a File, adjust/modify the data etc.
Since iOS 17 this is not possible anymore (previous versions worked iOS 16)? I cannot find any documentation on why or what changed on the os_log side.
private func setupPipes() {
inputPipe.fileHandleForReading.readabilityHandler = { [weak self] handler in
guard let strongSelf = self else { return }
let data = handler.availableData
strongSelf.queue.async(flags: .barrier) {
guard let fileHandle = try? FileHandle(forWritingTo: strongSelf.filePath) else { return }
fileHandle.seekToEndOfFile()
fileHandle.write(data)
try? fileHandle.close()
}
strongSelf.outputPipe.fileHandleForWriting.write(data)
}
dup2(STDERR_FILENO, outputPipe.fileHandleForWriting.fileDescriptor)
dup2(inputPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO)
}