Redirect Process Stdout to Apple System Log Facility in Swift

Redirect Process stdout to Apple System Log Facility in Swift

I finally managed to do this. Basically, we define a Pipe to catch the process output and, in an handler, call the OS function os_log with the data read:

let pipe = Pipe()
let outHandle = pipe.fileHandleForReading

outHandle.readabilityHandler = { pipe in
if let line = String(data: pipe.availableData, encoding: .utf8) {
// Define the placeholder as public, otherwise the Console obfuscate it
os_log("%{public}@", line)
}
}

let task = Process()
task.launchPath = "subprocess"
task.standardOutput = pipe // Redirect stdout to our pipe
task.launch()

In development, it is displayed in the Xcode console ; and when deployed it is redirected to the Apple Log System.

Swift macOS App - Enable Info/Debug Logging in Apple Console App

I faced the same problem. Info and debug level messages must be activated in the Console application: Console > Action > Include Info Messages and Include Debug Messages.

Take a look at Apple documentation at Include info or debug messages.

The following untracked working tree files would be overwritten by merge, but I don't care

The problem is that you are not tracking the files locally but identical files are tracked remotely so in order to "pull" your system would be forced to overwrite the local files which are not version controlled.

Try running

git add * 
git stash
git pull

This will track all files, remove all of your local changes to those files, and then get the files from the server.



Related Topics



Leave a reply



Submit