'Showing `print` logs for SwiftUI apps without XCode

I have simple SwiftUI.App for MacOS where I use print for debug logs. As far as I understand I should use os_log for regular "unified" logging, but can use print for my personal debug logs that will be excluded from releases of my app.

import SwiftUI

@main
struct Main: App {
    var body: some Scene {
        WindowGroup {
            Button("Debug") {
                print("print")
                NSLog("NSLog")
                os_log("os_log")
            }
        }
    }
}

Running this app I can see some logs in the Console.app on MacOS. It shows the entries for NSLog and os_log but not the print entry. The Console.app was the only place where I could see logs at all. Actually I want to see all logs on the command line, as I am used to from console applications (e.g., try swift <(echo 'print("success")')).

I start my app using open MyApp.app with the app binary located at ./MyApp.app/Contents/MacOS/MyApp. I also tried opening it with open MyApp.app -W to avoid it getting detached to the background and expecting some console output. However, there was none.

Which leads me to the following questions:

  1. Where can I see the print output my swift build -c debug builds in general (without XCode)?
  2. How can I make this SwiftUI.App log to the console when running from the command line?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source