CFNetwork diagnostics logs are empty while debugging on iPhone

I'm looking for an easy way how to figure out which requests are blocked by ATS on my device.

According to CFNetwork Diagnostic Logging I can do it by enabling CFNETWORK_DIAGNOSTICS environment variable and thats perfectly works for simulator - I can see log file by path that provided in console and log file is not empty.

But I have faced an issue that I cannot extract this logs just by fetching them in NSLibraryDirectory on iPhone. Logs are created on iPhone, but they are empty.

Is there any way to access this log file on device or extract information in this log programatically?

In addition, It seems like extracting .xcappdata with cfnetwork logs via Xcode download container is not working also because all cfnetwork logs are zero bytes size (but it should work as mentioned in CFNetwork Diagnostic Logging).

I have tried it on XCode 7.3.1/8.0/8.1 with iPhone SE iOS 10.0 & iPhone 5 iOS 10.1

Are there any ways to fix it?

Replies

Well, that’s exciting. It seems that CFNetwork diagnostics has only partially made the jump to the unified logging system that we added in iOS 10 and friends. You should definitely file bugs requesting support for the specific use cases that you care about. I’ve filed my own bugs against QA1887 (r. 29024477) and CFNetwork diagnostic itself (r. 29024490).

As things currently stand it is possible to get at the logs via sysdiagnose. Here’s what I did:

  1. I ran my app with

    CFNETWORK_DIAGNOSTICS
    set to 3.
  2. I ran a simple NSURLSession task in order to generate some logging.

  3. I grabbed a sysdiagnose, per the instructions on the Profiles and Logs page.

  4. I used

    log
    to filter the sysdiagnose for CFNetwork diagnostic messages.

Here’s an example of what I saw:

$ log show --start '2016-10-31 11:00:00' --predicate 'eventMessage BEGINSWITH "CFNetwork Diagnostics"' /Users/quinn/Library/Logs/CrashReporter/MobileDevice/Vanderspool/DiagnosticLogs/sysdiagnose/sysdiagnose_2016.10.31_11-12-28+0000/system_logs.logarchive
==========
/Users/quinn/Library/Logs/CrashReporter/MobileDevice/Vanderspool/DiagnosticLogs/sysdiagnose/sysdiagnose_2016.10.31_11-12-28+0000/system_logs.logarchive
==========
Skipping info and debug messages, pass --info and/or --debug to include.
Filtering the log data using "eventMessage BEGINSWITH "CFNetwork Diagnostics""
Timestamp                      Thread    Type        Activity            PID   
2016-10-31 11:01:40.995453+0000 0x2538f2  Default    0x0                  2498  QTestbed: (CFNetwork) CFNetwork Diagnostics [3:1] 11:01:40.990 {
LoaderWhatToDo: (null)
      Request: <CFURL 0x1700ccbe0 [0x1b4f41bb8]>{string = https://forums.developer.apple.com/, encoding = 134217984, base = (null)}
  CachePolicy: 1
      WhatToDo: originload
  CreateToNow: 0.00222s
} [3:1]
…
--------------------------------------------------------------------------------------------------------------------
Log      - Default:        163, Info:                0, Debug:            0, Error:          0, Fault:          0
Activity - Create:          0, Transition:          0, Actions:          0

You should be able to do similar things with the new Console app in macOS 10.12, although I haven’t tried that myself yet.

Share and Enjoy

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

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