Logger API iOS14

I am trying to use the Logger api instead of CocoaLumberjack. In the WWDC 2020 video it states that log messages will display in the Xcode debug console as well as the device logs. However, I cannot see any of these messages in Xcode. Does anyone have any insight on this?

Answered by G_Frank in 715080022

You are correct! It does work when I create an app from scratch. When I try to apply it as simply as you have done it above in my professional commercial app I cannot get it to print. I will investigate further. Thanks for your help.

However, I cannot see any of these messages in Xcode.

This is working for me. Here’s what I did:

  1. Using Xcode 13.4 I created a test app from the iOS > App template.

  2. I changed the view controller to look like this:

    class ViewController: UIViewController {
    
        let log = Logger(subsystem: "com.example.apple-samplecode.Test706735", category: "app")
    
        override func viewDidLoad() {
            super.viewDidLoad()
            log.debug("Hello Cruel World!")
        
        }
    }
    
  3. I ran it on an iOS 15.5 device.

It printed:

2022-05-30 08:50:45.453975+0100 Test706735[2974:280664] [app] Hello Cruel World!

I don’t have an iOS 14 device handy to test there, but I don’t think that’ll make a difference. Logger is just a wrapper around the standard system logging API and it’s that API that determines whether entries gets written to stderr.

Note that the Xcode console does not monitor the system log per se, but rather it captures text written to stdout and stderr. Logger and friends do not, by default, write to stderr. Xcode explicitly enables this by setting the OS_ACTIVITY_DT_MODE environment variable. There are some limitations here, for example, this only affects log entries coming from the main executable. The best way to monitor the system log is with the Console app or log stream. Both of these support proper filtering.

For more logging tidbits, see Your Friend the System Log.

Share and Enjoy

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

Accepted Answer

You are correct! It does work when I create an app from scratch. When I try to apply it as simply as you have done it above in my professional commercial app I cannot get it to print. I will investigate further. Thanks for your help.

I will investigate further

Cool. Let us know how you get along.

Also I want to clarify this bit:

There are some limitations here, for example, this only affects log entries coming from the main executable.

That’s not quite right. Log points from frameworks embedded in your app are also included. I can’t remember the exact details here but the above sentence should end this doesn’t affect log entries coming from system libraries.

Share and Enjoy

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

Logger API iOS14
 
 
Q