I have read several times
- https://developer.apple.com/forums/thread/705868
- https://developer.apple.com/forums/thread/705810
- https://developer.apple.com/documentation/os/logging/generating_log_messages_from_your_code#3665948
From what I understand code like this:
import SwiftUI
import OSLog
struct ContentView: View {
private static let logger = Logger(subsystem: "HCP", category: "ContentView")
var myprivateData: Date { Date() }
var myprivateData2: String { "bank-account-111-222-333" }
let myprivateData3: String = "bank-account-111-222-333"
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
.onAppear(perform: {
Self.logger.info("test info")
Self.logger.info("test info \(myprivateData)")
Self.logger.info("test info \(myprivateData2)")
Self.logger.info("test info \(myprivateData3)")
Self.logger.info("test info")
Self.logger.info("test info \(myprivateData, privacy: .private)")
Self.logger.info("test info \(myprivateData2, privacy: .private)")
Self.logger.info("test info \(myprivateData3, privacy: .private)")
})
}
}
Should result in somewhat redacted log messages, so my expectation would be that dynamic strings
Self.logger.info("test info1")
Self.logger.info("test info2 \(myprivateData)")
Self.logger.info("test info3 \(myprivateData2)")
Self.logger.info("test info4 \(myprivateData3)")
would result in logs like:
info 21:29:07.877698+0200 TestOsLogger test info1
info 21:29:07.877757+0200 TestOsLogger test info2 <private>
info 21:29:07.877800+0200 TestOsLogger test info3 <private>
info 21:29:07.877835+0200 TestOsLogger test info4 <private>
instead I get
info 21:29:07.874356+0200 TestOsLogger test info1
info 21:29:07.877531+0200 TestOsLogger test info2 <private>
info 21:29:07.877615+0200 TestOsLogger test info3 bank-account-111-222-333
info 21:29:07.877656+0200 TestOsLogger test info4 bank-account-111-222-333
where clearly date object got redacted, but string not really.
Adding privacy: .private
helps here, but it is still a different behavior from what I expected after reading docs.
Is that a change or rather my misunderstanding? Eskimo for the rescue?