Logging not redacting strings in Xcode

This is probably a minor point because it wouldn't affect distributed binaries, but I thought I'd mention it in case the behavior is unexpected.

After watching WWDC 20202 Explore logging in Swift, I tried some simple examples in a Mac command-line app. I was surprised to see the strings were all printed just fine. There was no redaction. At least when running the program from Xcode.

(Even using the old os_log() approach showed the strings without needing to add %{public}@.)

However, if I run the program from a Terminal shell, the string arguments are properly redacted.

I actually like this behavior (showing more while running in Xcode), but I thought I'd just raise the issue. Sample code and screenshot from Console are shown below.

import Foundation
import os

let logger = Logger(subsystem: "com.example.logging_test", category: "hello")

let greeting = "Hello"
let personName = "World"

logger.log("\(greeting), \(personName)")
logger.log("\(greeting, privacy: .private), \(personName)")
logger.log("\(greeting, privacy: .public), \(personName)")
os_log("%@, %@", greeting, personName)

Replies

This is expected behaviour. Xcode sets an environment variable (OS_ACTIVITY_DT_MODE) that causes significant behaviour changes in the system log implementation within your process. I added more details about this to Your Friend the System Log.

Share and Enjoy

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