During normal development you can set this environment variable via Xcode's scheme editor. If you need to investigate problems outside of Xcode, you can set it programmatically using the code shown in Listing 1.
Listing 1 Programmatically enabling CFNetwork diagnostic logging
setenv("CFNETWORK_DIAGNOSTICS", "3", 1);
You should do this right at the beginning of the app's launch sequence. Normally putting this at the start of main is sufficient, but if you have C++ static initialisers that use CFNetwork you'll have to run it before them.
CFNetwork diagnostic logging starts up when you first use CFNetwork—or any framework, like Foundation, that uses CFNetwork—at which point it will print a message like that shown in Listing 2.
Listing 2 An example of the CFNetwork diagnostic logging startup message
2014-10-28 14:23:37.115 QTestbed[2626:60b] CFNetwork diagnostics log file created at: /private/var/mobile/Applications/76531F40-3291-4565-8C75-0438052C83BC/Library/Logs/CrashReporter/CFNetwork_com.example.apple-samplecode.QTestbed_2626.nwlrb