iosswiftxcodeloggingnslog

How to access a user's logging info in iOS?


I've read about the Unified Logging Framework as well as the new iOS 14 API regarding logging on devices, but I can't find anything that would enable me to write a log on a user's device to troubleshoot an issue, and for me to be able to review it? What is the current state of the art for doing this inside the Apple framework, or 3rd party library?


Solution

  • What you have read is how to write a log on the user's device. When you use os_log or the new Logger, and you log with anything but the lowest level, it is written into the log. The user can extract it using the log command in the Terminal. Of course you need to give instructions, so practice on your own device first.

    For instance, if I hook my phone, TheMattPhone, to the computer, and say in the Terminal

    sudo log collect --device-name "TheMattPhone" --last 1h
    

    ...then the result is that my home directory now contains a file called system_logs.logarchive. The user can zip that up and send it to you.

    There are much more sophisticated commands that can extract just your app's logs, or even particular logs, depending on how you've configured the logger.

    Note that the log written to the file will be redacted unless you mark interpolated material as public.