16

I am building a Swift 5 application with XCode 10.3. For this, I have a framework which contains a implementation for a logsystem (for debugging purposes). The default implementation for this logsystem is based on OSLog/os_log. When using the system in the consuming app, then none of the logs appear in the Console app. However, when placing breakpoints, I can see that the os_log statement (see code example below) is reached and that the correct parameters are passed on to the os_log function. However, when I use os_log or NSLog in the host application, then they do show up.

I have verified that it is not an issue with the LogSystem / DefaultLogImplementation types as all of the breakpoints that need to be hit, are hit, and all unit tests are green. In addition, the os_log statement is reached and executed, but the logs do not appear. I have verified that all messages are shown in the console app, I have verified that I have selected the correct device, I have tried multiple filters (and even dug through all the logs without filters enabled)...

Can anyone help / give a pointer at what the issue may be? I am currently suspecting that there is a bug in the implementation of OSLog/os_log.

Code sample

App-side code, which consumes code similar to the examples provided below

class SomeClass {
    private let logSystem = LogSystem()

    func doSomethingImportant() {
        // Do important stuff and log the result
        logSystem.debug("Finished process with result \(result)")
    }

}

Framework-side code, which is consumed by the app

public class LogSystem {

    private let logImplementation: LogImplementation

    init(_ logImplementation: LogImplementation = DefaultLogImplementation()) {
        self.logImplementation = logImplementation
    }

    public func debug(_ message: String) {
        logImplementation.log(message, type: .debug) // And some other parameters...
    }

    public func error(_ message: String) {
        // Similar to debug(:)...
    }

}

public protocol LogImplementation {
    func log(_ message: String, type: LogType, ...other parameters...)
}

public class DefaultLogImplementation: LogImplementation {
    func log(_ message: String, type: LogType, ...other parameters...) {
        let parsedType = parseLogType(type) // Function that parses LogType to OSLogType
        let log = OSLog(subsystem: "my.subsystem.domain", category: "myCategory")
        os_log("%{private}@", log: log, type: parsedType, message) // Breakpoint here is reached, but log does not appear in console app (even with debugger attached, which should remove the effect of "%{private}%". Either way, at the very least censored logs should still appear in console app.
    }
}

Additional info

Swift version: 5.0

XCode version: 10.3

Target device: iOS 12.2 iPhone X simulator

NSLog appears in console app: Yes

Selected correct device in console app: Yes

Correct filters: Yes

Update 2019-08-16 13:00 (Amsterdam time)

It appears that only .debug level messages are not appearing in the Console app. This bug occurs when using any simulator device in combination with OSLog. I have tried several commands to fix this:

sudo log config --mode level:debug,persist:debug

sudo log config --subsystem my.reverse.domain.name --mode level:debug,persist:debug

Neither of them fixed the issue. In fact, not a single debug-level message of the simulator is showing up in the console app (not even from iOS itself). Yes, the option to show .info and .debug level messages is enabled.

I tried setting the log-level for the simulator specifically through the following command:

xcrun simctl spawn booted log config --mode level:debug

But this result in an error:

log: Simulator unable to set system mode

13
  • Are you filtering on the right subsystem? Commented Aug 15, 2019 at 12:52
  • @matt definitely. I use a wrapper on top of os_log made by one of the frameworks, and when I use the wrapper then the logs from my own application dont show up either. (wrapper is written by myself as well). Commented Aug 15, 2019 at 12:58
  • 1
    Well then it sounds like the wrapper is at fault. But you have not shown it. You haven't shown any code or given any information as to how we might reproduce the problem you are having. Commented Aug 15, 2019 at 15:21
  • @matt I haven't shown it because I know the wrapper is not at fault. I breakpointed the crap out of it. I can see the wrapper function being called with all expected parameters, and I can see that os_log is also called correctly. But they don't appear in the debug console nor in the console app. In fact, when I copy the exact wrapper to my project it even works. I also verified that the framework the wrapper is in, doesn't disable logging or the wrapper. To me this seems like a bug in Swift or in the compiler, but I want to verify that I did not miss anything before making that assumption. Commented Aug 15, 2019 at 15:52
  • Well, unless you can provide some sort of reproducible example, it's hard to "verify" anything and it isn't clear why you're asking this question at all. Just go ahead and assume away. :) If you think you've got a case for a bug report to Apple, file it. Commented Aug 15, 2019 at 16:02

3 Answers 3

18

In the console app, there are two options to include / hide debug and info messages:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Thx you saved me a lot of precious time!
Also - don't be surprised, if entries in Console app (when debugging app running on is running on phone) appears ~25-30 secs later than entries in log are recorded.
Thanks! Still the correct answer. Saved me from descending into console debugging madness.
7

I've spoken with an Apple DTS Engineer and it's a know issues not being able to see debug messages using a simulator (in Xcode 11 too): open a feedback

2 Comments

I've been testing this in March 2021 and see exactly the same bugs with Xcode 12.5. Reported to Apple via FB9028830. twitter.com/steipete/status/1367424733113901059?s=21
I am using Monterey 12.6 and sometimes it works and sometimes not works for me, it's really interesting
0

Please note that while debug messages may not work on simulators, they are fully functional on physical devices. It's important to keep this in mind when troubleshooting and testing your app.

  • XCode - Version 14.3 (14E222b)
  • Console App - Version 1.1 (8.1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.