Xcode 15 Structured log always redacting <private> strings

This is the opposite of https://developer.apple.com/forums/thread/726354 really, and I've read both of the Recording Private Data in the System Log and Your Friend, the System Log threads, but I still can't solve my problem.

The structured log always seems to redact private values to <private>

If I set OS_ACTIVITY_DT_MODE=1 in my environment (it's not set anymore by Xcode, at least not for my projects) then the logs are unredacted as I would expect, but structured logging is turned off.

Is there a way to have the unredacted strings in the log when the app is running under Xcode and still get the nice structured log output? I don't want the unredacted logs when the app runs normally, but I'd like them under Xcode. At the moment, I'm having to explicitly make everything public, which defeats the whole purpose of the system.

Xcode 15 Structured log always redacting <private> strings

Is your app running on macOS? Or iOS?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It's a Cocoa app running on macOS.

Current OS is Ventura, and Xcode 15

Accepted Answer

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>

Thank you, that's working.

One more question: in your example you explicitly set Enable-Private-Data for the app log category. Is it possible to enable it for all categories without having to list them all explicitly?

thanks again

Is it possible to enable it for all categories without having to list them all explicitly?

Yes. Quoting the os_log man page (section 5):

The special DEFAULT-OPTIONS category key can be used to define common settings for all categories in a subsystem.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Xcode 15 Structured log always redacting &lt;private&gt; strings
 
 
Q