I’m not aware of any way to make it work with non-Apple profiles.
I wasn’t happy with that response so I raised this issue with the OSLog team. They pointed me to something I didn’t know about, namely the OSLogPreferences
property for your Info.plist
. You can read more about this in the os_log(5)
man page.
Just to be sure that this works on iOS, I created a tiny test project to exercise it. In my code I set up two log objects:
let logWaffle = Logger(subsystem: "com.example.apple-samplecode.Test702941", category: "waffle")
let logVarnish = Logger(subsystem: "com.example.apple-samplecode.Test702941", category: "varnish")
Note I’m using the new Logger
API but that doesn’t change things. This feature works with all the other APIs that funnel through the unified logging system.
I then added a button that logs to each log object:
let nowStr = "\(Date.now)"
logWaffle.log( "waffle default: \(nowStr), private: \(nowStr, privacy: .private), public: \(nowStr, privacy: .public)")
logVarnish.log("varnish default: \(nowStr), private: \(nowStr, privacy: .private), public: \(nowStr, privacy: .public)")
Note how I’m exercising three privacy settings: .auto
, .private
, and .public
.
At this point I ran the app and clicked the button to generate some log entries.
IMPORTANT To run the app:
-
Choose Product > Run.
-
Then Product > Stop.
-
Then run the app from the iOS device’s Home screen.
This is necessary because Xcode customises the system log environment for apps that it runs, but you want to see the standard behaviour.
On clicking my test button I see the following in Console:
type: default
time: 12:26:55.027220+0000
process: Test702941
subsystem: com.example.apple-samplecode.Test702941
category: waffle
message: waffle default: <private>, private: <private>, public: 2022-03-25 12:26:55 +0000
type: default
time: 12:26:55.027328+0000
process: Test702941
subsystem: com.example.apple-samplecode.Test702941
category: varnish
message: varnish default: <private>, private: <private>, public: 2022-03-25 12:26:55 +0000
Both log objects display the same info, with the string redacted in the .auto
and the .private
cases, which is what you’d expect.
I then added this to my app’s Info.plist
file:
<key>OSLogPreferences</key>
<dict>
<key>com.example.apple-samplecode.Test702941</key>
<dict>
<key>waffle</key>
<dict>
<key>Enable-Private-Data</key>
<true/>
</dict>
</dict>
</dict>
This unredacts the private data, but only for the waffle
category. I ran the test again (using the run-stop-run dance, of course) and now I see this:
type: default
time: 12:11:03.947032+0000
process: Test702941
subsystem: com.example.apple-samplecode.Test702941
category: waffle
message: waffle default: 2022-03-25 12:11:03 +0000, private: 2022-03-25 12:11:03 +0000, public: 2022-03-25 12:11:03 +0000
type: default
time: 12:11:03.947115+0000
process: Test702941
subsystem: com.example.apple-samplecode.Test702941
category: varnish
message: varnish default: <private>, private: <private>, public: 2022-03-25 12:11:03 +0000
As you can see, in the waffle
category the string is no longer redacted at all.
In the above I’ve used private data redaction as an example but this property list item gives you access to all the configuration options supported by the unified logging system. The os_log(5)
man page has all the details.
Finally, I’ve filed a bug (r. 90831886) to get this info added to the Customizing Logging Behavior While Debugging page, where folks are more likely to find it.
I didn’t test this with an NE provider but I believe it’ll work there as well. Add the property to the provider’s Info.plist
, not that of the container app.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"