6 Replies
      Latest reply on Sep 7, 2018 3:09 AM by tomnaz
      Glauco Level 1 Level 1 (0 points)

        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 caller information for you, so there's no longer any need for you to 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


        What am I missing?

        • Re: os_log source file and line numbers
          eskimo Apple Staff Apple Staff (13,345 points)

          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");

            • Re: os_log source file and line numbers
              huapapojt Level 1 Level 1 (0 points)

              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


              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