os_log source file and line numbers

Based on https://developer.apple.com/videos/play/wwdc2016/721/ my understanding is that we don't need to inject source file name and line number into the message because the system will do that for us.

"....Another important thing is logging system collects callerinformation for you, so there's no longer any need for youto pass file, line to identify where this is called from. We are automatically collecting that for you....."


// File.m

@implementation Foo

- (void)log
{
     os_log(OS_LOG_DEFAULT, "This is a log message."); // it doesn't log the file name and the line number
}


@end


What am I missing?

Replies

I ran a simple test and it’s working for me. Here’s what I did:

  1. I created a small command line tool with the code shown below.

  2. I use the command shown below to look for those log entries.

Here’s the output I see:

$ log stream --source --predicate 'eventMessage contains "qqq"'
Filtering the log data using "eventMessage CONTAINS "qqq""
Timestamp                      Thread    Type        Activity            PID   
2016-12-11 22:50:45.871155+0100 0xc16b8    Default    0x0                  12425  <xxot`main (main.m:4)> qqq

The log entry is shown as coming from line 4 of

main.m
in the
xxot
image (the name of my tool).

I suspect you’re dealing with a more complex case than what I’ve described here. If you can post specifics about your issue, I’ll see if I can explain what’s going on.

Share and Enjoy

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

let myEmail = "eskimo" + "1" + "@apple.com"
#import <os/log.h>

extern int main() {
    os_log(OS_LOG_DEFAULT, "qqq");
}

Thank you for the answer. I also have two questions:

- When will this be available in Swift 3?

- Is there a way to view file and line number directly in Console? If not so, when will this be available?


I tried something similar to what's inside the forum by creating a simple command-line tool Xcode project:


    import Foundation
    import os.log
    os_log("rrrr")


and type the following in Terminal: `log stream --source --predicate 'eventMessage contains "rrrr"'`, and I got this:



    Timestamp                       Thread     Type        Activity             PID
    2017-02-18 17:58:46.012381+0700 0x5067d    Default     0x0                  5637   <testLogSwift`_swift_os_log> rrrr



in contrast to what I got in C/C++ version, which shows the file and line number:


    Timestamp                       Thread     Type        Activity             PID
    2017-02-18 17:55:05.056103+0700 0x4aa01    Default     0x0                  5218   <testLogging`main (main.cpp:13)> qqq



Furthermore, I couldn't see the file and line number in either cases from the Console.


[1]: https://forums.developer.apple.com/thread/69113

When will this be available in Swift 3?

I can confirm that I’m seeing the same result you’re seeing. Clearly this is a bug that’s worth filing. Please post your bug number, just for the record.

Is there a way to view file and line number directly in Console?

Not that I know of.

If not so, when will this be available?

I can’t talk about the future.

Share and Enjoy

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

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

I submitted the bug report, and this is the number: 30648811.

I wondered if there was any update on this one?


The WW video was released over 2 years ago at this point. Thanks!

Any news if the fix will be applied in the new Xcode / Mojave release maybe? The console still doesn't show all the information.