Console app not showing os_log messages from iOS when not run via Xcode

I have os_log statements in my app. With my phone connected to the Mac, when I run the app through XCode, open Console app, those logs are shown. However, when I'm launching the app on its own, those logs don't appear in Console (phone still connected).

Am I missing something very basic? Please help.

In Console, make sure that:

  1. You have your iPhone selected on the left.

  2. You have Include Info Messages and Include Debug Messages enabled on the Action menu.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I had already done the above steps. Still the same behaviour, unfortunately.

I had already done the above steps.

OK.

I just tried this here in my office and it’s working as expected. Specifically:

  1. On macOS 13.2.1 using Xcode 14.2 with an iOS 16.3.1 device attached…

  2. I launched Console, selected my device on the left, pasted subsystem:com.example.apple-samplecode.Test727380 into the search field, and clicked “Start streaming”.

  3. In Xcode, I created a new test project with a button wired up to this code:

    import UIKit
    import OSLog
    
    class MyViewController … {
    
        let logger = Logger(subsystem: "com.example.apple-samplecode.Test727380", category: "app")
    
        func test() {
            logger.log("Hello Cruel World!")
        }
    
        … other stuff …
    }
    
  4. With my device selected as the run destination, I chose Product > Run.

  5. In the app on the device, I tapped the Test button.

  6. In Console, I saw my log message:

    type: default
    time: 09:10:44.044219+0800
    process: Test727380
    subsystem: com.example.apple-samplecode.Test727380
    category: app
    message: Hello Cruel World!
    
  7. In Xcode, I chose Product > Stop.

  8. On the device, I launched the app from the Home screen.

  9. I repeated steps 5 and 6 and saw the new log message:

    type: default
    time: 09:11:14.362762+0800
    process: Test727380
    subsystem: com.example.apple-samplecode.Test727380
    category: app
    message: Hello Cruel World!
    

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Okay. I must have missed the OOP side of logging. Could you please swap in the following and see if it still works?

func test() {
   let oslog = OSLog(subsystem: "com.example.apple-samplecode.Test727380", category: "app")
   os_log("%s", log: oslog, type: .info, "Hello Cruel World!")
}

In the meantime, I'll try it out like in your example. Thanks for it.

Do you know whether the subsystem needs to match the app bundle ID? Is

Okay, so your version is working. Thanks again for the detailed examples (which I should've provided in the first place!)

I have a hunch why the old os_log is not outputting anything is related to how the unified logging system is handling privacy. Let's say in your example, if I am to put:

logger.log("Hello Cruel \(planet)!")

When running without Xcode, it will output Hello Cruel <private> to the Console. I'd have to add Hello Cruel \(planet, privacy: .public) for the full message to appear.

I assume, when using os_log with format specifiers (%s) and CvarArg, it treats the whole message as private, and that's why it's not outputting anything when run without Xcode. I don't know if there's a way to specify public for the os_log approach. One downside of using Logger is that it's bound to iOS 14, but we're supporting older versions.

Cheers

I assume, when using os_log with format specifiers (%s) and CVarArg, it treats the whole message as private

Yes. Logging like this:

os_log("%s", log: oslog, type: .info, "Hello Cruel World!")

is an anti-pattern because it defeats the optimisations done by the system log. I call this out in Your Friend the System Log.

I don't know if there's a way to specify public for the os_log approach.

There is, via the %{public}s syntax. See the os_log man page for details. However, that’s predicated on you using os_log correctly. If you use it as shown above, your entire log string will be public and that defeats the whole purpose of not recording private data.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

%{public}s works indeed. Thank you for the guidance. I'll see how to tailor it so as to log just non-sensitive data.

os_log(.info, "launched") appeared in the Console app (With Action->Include Info Messages checked) for me when using the simulator and launching the app from the home screen.

These did not appear:

print("launched")
os_log("launched")
os_log(.debug, "launched") // nothing even with Action->Include Info Debug checked!!!

ISTR the simulator thing being a known issue. Yep, here we go, that’s FB5342358. AFAICT it remains unresolved.

As far as the real device is concerned, it’s hard to offer a definitive answer without more details about your test setup. However, I ran my own test today and things work as I expected.

Specifically:

  1. Using Xcode 15.3 on macOS 14.4, I created a small test project with a button wired up to this code:

    print("QQQ print")
    os_log("QQQ os_log")
    os_log(.debug, "QQQ os_log debug")
    
  2. I ran the app on my iOS 17.4.1 device.

  3. I stopped it.

  4. I launched Console.

  5. I selected my iOS device on the left.

  6. I entered QQQ into the search field and pressed Return.

  7. I made sure that about Action > Include {Info,Debug} Messages menu items were enabled.

  8. I started streaming the log.

  9. On the iOS device, I launched my app from the Home screen.

  10. I tapped the test button.

  11. In Console, I saw these log entries:

type: default
time: 10:05:08.808129+0000
process: Test727380
category: <Missing Description>
message: QQQ os_log

type: debug
time: 10:05:08.808363+0000
process: Test727380
category: <Missing Description>
message: QQQ os_log debug

The QQQ print entry is missing because it uses print(…), which doesn’t go to the system log. The others are both present as expected.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Console app not showing os_log messages from iOS when not run via Xcode
 
 
Q