0

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?
Juve
  • 10,584
  • 14
  • 63
  • 90
  • [This question](https://stackoverflow.com/questions/13104588/how-to-get-stdout-into-console-app) might be of interest. – Joakim Danielson May 01 '22 at 17:06
  • Just run in Terminal `# ./MyApp.app/Contents/MacOS/MyApp` and you'll see all output. – Asperi May 01 '22 at 17:39
  • Thanks @Asperi `./MyApp.app/Contents/MacOS/MyApp` works for now. I had seen errors when calling the binary without `open` before. But now it works. I would still be interested where the `print` logs can be seen if I start my app regularly (not from the command line). – Juve May 01 '22 at 21:18

0 Answers0