Consider this snippet:
let log = Logger(subsystem: "com.example.apple-samplecode.Test738648", category: "app")
@IBAction
private func testAction(_ sender: Any) {
log.log("Hello Cruel World! pid: \(getpid()), proc: \(ProcessInfo.processInfo.processName)")
}
By default the proc
value is private and thus not recorded. This is true in both Xcode 15 and Console.
The easiest way to opt in to private data recording is the OSLogPreferences
mechanism discussed in Recording Private Data in the System Log. For example, if I add this to my Info.plist
:
<key>OSLogPreferences</key>
<dict>
<key>com.example.apple-samplecode.Test738648</key>
<dict>
<key>app</key>
<dict>
<key>Enable-Private-Data</key>
<true/>
</dict>
</dict>
</dict>
I see the private data in both places. I’m testing with Xcode 15.0 on macOS 13.5.2.
The main problem with this approach is that it’s hard to conditionalise out for your release builds. There are a couple of ways you could do that:
-
Customise the Info.plist File build setting to point to a different Info.plist
file.
-
Change tack, and use a configuration profile. I’ve pasted an example of such a profile below.
Personally, I’m a fan of the configuration profile approach because it means there’s no chance of you shipping a build that accidentally records private data.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadDescription</key>
<string>System Logging</string>
<key>PayloadDisplayName</key>
<string>System Logging</string>
<key>PayloadIdentifier</key>
<string>com.apple.system.logging.684C6584-DDFB-4DC5-AD4B-DF084028C248</string>
<key>PayloadType</key>
<string>com.apple.system.logging</string>
<key>PayloadUUID</key>
<string>684C6584-DDFB-4DC5-AD4B-DF084028C248</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>Subsystems</key>
<dict>
<key>com.example.apple-samplecode.Test738648</key>
<dict>
<key>app</key>
<dict>
<key>Enable-Private-Data</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</array>
<key>PayloadDescription</key>
<string>Enables logging for the Test738648 app.</string>
<key>PayloadDisplayName</key>
<string>Test738648 Enable Logging</string>
<key>PayloadIdentifier</key>
<string>Slimey.02BFD8E9-601F-40D3-96CF-8EA446D0ABD6</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>84BE502F-BB63-4D65-BBAF-64FCC31AA00A</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>