Console app not showing info and debug logs

I have a Swift 3 Cocoa application that uses Apple's Unified Logging, like this: -


    import os

    class MyClass
    {
        @available(OSX 10.12, *)
        static let scribe = OSLog(subsystem: "com.mycompany.myapp", category: "myapp")

        func SomeFunction(){
  
            if #available(OSX 10.12, *){
                os_log("Test Error Message", log: MyClass.scribe, type: .error)
            }

            if #available(OSX 10.12, *){
                os_log("Test Info Message", log: MyClass.scribe, type: .info)
            }

            if #available(OSX 10.12, *){
                os_log("Test Debug Message", log: MyClass.scribe, type: .debug)
            }
        }
    }



Within the Console application, both

Include Info Messages
and
Include Debug Messages
are turned on.


When

os_log
is called, only the
error
type message is visible in the Console application.

Using Terminal, with the command, all message types are visible in the Terminal output: -


sudo log stream --level debug


I've tried running the Console app as root, via sudo from the command line and the same issue occurs; no debug or info messages can be seen, even though they're set to being turned on under the Action menu.

Setting system-wide logging to be debug, has no effect on the Console application output:

sudo log config --mode level:debug


Please can someone tell me what I'm missing and how can I view debug and info messages in the Console application?

Well, that’s interesting. I can reproduce this problem on my main 10.12.5 machine. Which is weird because I definitely remember seeing those messages on earlier versions of 10.12. So I fired up some VMs and found the following:

  • Console shows info messages on the VM’s 10.12 snapshot

  • Console doesn’t show info messages on its 10.12.5 snapshot

I suspect that this is a known bug (r. 30733532) that’s reported fixed in the current 10.13 beta. Please give it a try there.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Quinn,


Thanks for getting back to me, I've never had Unified Logging working correctly since it was first introduced, at which time, it only showed logs in the console if we were logging out the stream in the Terminal at the same time.


As requested, I tried on 10.13 (17A306f) with a daemon application I'm developing. When the daemon was first loaded, after installing the application via a pkg, it failed to show any logs. I stopped the daemon (launchctl unload), ran the application from the command line and Console started working as expected. Following that, I restarted the daemon (launchctl load) and it continued working correctly. We'll continue testing around the initial install and let you know if we think there's an issue there and will file a report accordingly.


Should I file a report bug for 10.12.5, or is it likely to just be a repeat?


One other question, the daemon is written in Swift 3 and we still see 'private', printed even though we're using the public attributes %{public}s or %{public}@. Can you tell me if this should work now, in Swift? If I recall correctly, it didn't when Unified Logging was first announced.


Thanks.

Should I file a report bug for 10.12.5, or is it likely to just be a repeat?

At this point I doubt there’s much benefit to filing a 10.12.x bug for this.

in Swift 3 … we still see 'private', printed even though we're using the public attributes %{public}s or %{public}@. Can you tell me if this should work now, in Swift?

I believe this is still broken )-: It’s definitely worth filing a bug about this one though; it’ll probably get dup’d to an existing bug (r. 33376006) but it’d be helpful to record your specific circumstances (for example, the fact you’re working on macOS and that you’ve tested it on the current 10.13 beta).

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks again Quinn for the rapid response.

Bug submitted: 33423866

I'm running 10.14 Beta (18A336e) and was seeing similar behavior, but was able to view the debug messages in the console when I also used the persist option


sudo log config --mode "level:debug,persist:debug" --subsystem com.myapp.myfancylog --category myCategory


This only worked for macOS apps, both command line and cocoa apps. iPhone logs I could never get to show the debug logs anywhere but the xcode console. As another note, I'm not sure if setting the category made any difference.

Any update on this issue? I am running the GA of Xcode 10 and I am still seeing this issue.

Which issue specifically? There’s been a few discussed on this thread.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

This should work:


xcrun simctl spawn booted log stream --debug --predicate 'subsystem == "com.example.yourapp"'


But yeah, the issue still persists and it's quite a shame. I am not sure if a bug has been filed for this, so should I create one? I am quite honestly amazed that this still seems to be an issue.

But yeah, the issue still persists and it's quite a shame.

What issue are you referring to here? The original issue that started this thread — that is, the inability so see Info and Debug log entries in the Console app (r. 30733532) — was fixed years ago. And the issue reported by nteissler was in a 10.14 beta, and my experience is that it was fixed before 10.14 shipped.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Sample problem here, the message only shows up in the xcode console but not the console.app


import Foundation
import os

public func debug_log(_ category: String = "application", args: Any...) {
  let config = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "application", category: category)
  var string = String()
  for arg in args {
    string.append(String(describing: arg))
    string.append(" ")
  }
  os_log("%s", log: config, type: .debug, string)
}


Mind you this one shows in both xcode & console

os_log("%s", string)


Xcode 10.1, swift 4.x

macOS 10.14.3

This works on my machine. I took your code, put it into a test app, and ran it on my Mac (I’m still on 10.14.1, but I very much doubted this has changed between that and 10.14.3). I then logged two lines:

NSLog("QQQ NSLog")
debug_log("QQQ OSLog")

I ran the app from Xcode (10.1) and in Xcode’s Console pane I see this:

2019-01-24 09:58:56.179537+0000 xxsm[57057:4028867] QQQ NSLog
2019-01-24 09:58:56.179993+0000 xxsm[57057:4028867] [QQQ OSLog]

and in the Console app I see this:

default
09:58:56.179573 +0000
xxsm
57057
QQQ NSLog

debug
09:58:56.180018 +0000
xxsm
57057
QQQ OSLog

[DevForums doesn’t support screen shots, alas, so I’ve done what I usually do with Console log entries, that is, replace all the tabs with line breaks so that they’re easier to read, and that inserted a line break between each log entry.]

I’m not sure what’s going on in your setup, but this is working for me.

Mind you this one shows in both xcode & console

Are you sure you’ve enabled both Action > Include Info Messages and Action > Include Debug Messages in Console? Calling

os_log
without an explicit
type
argument defaults to
.default
, which will always show up in Console. If you want to see
.debug
messages, you have to opt in.

ps Your wrapper around

os_log
is problematic:
  • You’re creating a new

    OSLog
    object for each log entry. That’s a really bad idea.
    OSLog
    objects are meant to be long-lived, and by creating a new one each time you’re really hurting your performance.
  • You have a wrapper around

    os_log
    , which undermines some of its best features. Rather than do that I recommend that you call
    os_log
    directly at each point you log [1]. You can improve the ergonomics of this by using an extension on
    OSLog
    for your common subsystems.
    extension OSLog {
        static let beer: OSLog = OSLog(subsystem: "com.example.apple-samplecode.myapp", category: "beer")
    }
    
    
    os_log(.debug, log: .beer, "%d bottles of beer on the wall", 99)

    .

  • To avoid conflicts with other apps, your subsystem should use reverse DNS name notation (that is, not

    application
    ).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] In C based languages you create a wrapper using a macro, but that’s not possible in Swift.

opting into debug/info messages via the console doesn't work, only if message is sent as .default or .error shows up.

Weird, this definitely works on my machine and I can’t think of any reason why it would vary from machine to machine.

Are these log entries generated on your local Mac? Or on an iOS device connected via USB?

If the log messages are generated on your Mac, run

log stream
to see if the messages show up there (see the
log
man page for details).

If the log messages are coming from iOS over USB, copy your log generation code into a small Mac program (and command-line tool will work) and see if that affects things.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Could this be an issue with the simulator only?


This is what I see on macOS 10.14.2/Xcode 10.1 with an iPhone XR iOS 12.1 simulator. Created a brand new project and added the following os_log lines as a test:


os_log(.debug, "Debug")
os_log(.info, "Info")
os_log("Default")
os_log(.error, "Error")
os_log(.fault, "Fault")


Xcode integrated lldb console output looks like this:


2019-01-29 09:57:19.231834-0500 os_log[19897:6448097] Debug
2019-01-29 09:57:22.628014-0500 os_log[19897:6448097] Info
2019-01-29 09:57:22.628053-0500 os_log[19897:6448303] XPC connection interrupted
2019-01-29 09:57:24.294260-0500 os_log[19897:6448097] Default
2019-01-29 09:57:25.784404-0500 os_log[19897:6448097] Error
2019-01-29 09:57:26.384291-0500 os_log[19897:6448097] Fault


Console App output looks like this:


info Info os_log os_log 09:57:22.628099 -0500
info Info os_log os_log 09:57:22.628099 -0500
default Default os_log os_log 09:57:24.294361 -0500
default Default os_log os_log 09:57:24.294361 -0500
error Error os_log os_log 09:57:25.784490 -0500
error Error os_log os_log 09:57:25.784490 -0500
fault Fault os_log os_log 09:57:26.384440 -0500
fault Fault os_log os_log 09:57:26.384440 -0500


Action menu has Include Info Message and Include Debug Messages turned on and the Search/Filter bar just has Library is os_log (the name of the sample xcode project I created to test).

Could this be an issue with the simulator only?

I know know if that’s what other folks on this thread are talking about — certainly none of them have mentioned that they’re using the simulator — but I can reproduce the problem that you’ve described. Yay! Well, I mean Boo! because it’s a bug, but Yay! because it’s easily reproduced.

I encourage you to file a bug report about this particular edge case. Please post your bug number, just for the record.

As to workarounds, you can see these log messages by running the

log
tool in the context of your simulator. For example:
$ xcrun simctl spawn DB0E33F1-289A-4DE1-A004-64F7ED04E05E log stream --level debug
…
2019-01-30 10:13:31.218490+0000 0x858df2  Debug    0x0       15275  0  xxsi: QQQ Debug
2019-01-30 10:13:31.218606+0000 0x858df2  Info     0x0       15275  0  xxsi: QQQ Info
2019-01-30 10:13:31.218691+0000 0x858df2  Default  0x0       15275  0  xxsi: QQQ Default
2019-01-30 10:13:31.218777+0000 0x858df2  Error    0x0       15275  0  xxsi: QQQ Error
2019-01-30 10:13:31.218927+0000 0x858df2  Fault    0x3a5382  15275  0  xxsi: QQQ Fault
…

Note:

  • DB0E33F1-289A-4DE1-A004-64F7ED04E05E
    is the UUID of my 12.1 simulator; you can get this using
    xcrun simctl list
    .
  • I added

    QQQ
    to me log messages to make them easier to spot.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Console app not showing info and debug logs
 
 
Q