I'd like to reproduce the behavior of the new Swift logging features where interpolated values in a String show as <private> instead of their actual value for a custom logger that I use in my app.
For example:
let accountNumber = 12345
log("User account number: \(accountNumber)")
// User account number: 12345 ← leaking personal information
Instead I'd like this result:
// User account number: <private>
I looked at extending String.StringInterpolation and it works great for custom types, but I could not figure out how to hook into the default interpolation, since I need to catch ANY interpolated type.
Here is an example with a custom argument name, but it's too easy to forget to specify that:
extension String.StringInterpolation
{
mutating func appendInterpolation<T>(private value:T) {
let literal = "<private>"
appendLiteral(literal)
}
}
log("User account number: \(private: accountNumber)") // Too easy to forget "private:"...
// User account number: <private>