8

In Swift, I use code like this:

let logger = Logger()
let someInfo = "information"
logger.warning("blah: \(someInfo)")

but the console output shows: blah: \<private>

unless I change the final line to:

logger.warning("blah: \(someInfo, privacy: .public)")

I'm wondering if there is a way to make the default to be .public -- while I am developing my app, I want to see all of the messages -- without having to include the privacy: .public everywhere.

Edit. I am using a workaround for now, but I don't love the solution, and hoping there is some official support, the workaround I'm using is a method like this:

static func logwarn(_ message: String) {
    let logger = Logger()
    logger.warning("\(message, privacy: .public)")
}

then I call logwarn, and can #ifdef it so that it's implemented differently (ie, not public) in release code.

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
Kem Mason
  • 1,548
  • 17
  • 26
  • A possible solution was mentioned some time ago in the "Ask Differen Chat" https://chat.stackexchange.com/transcript/message/61983334#61983334. I did not try it so I cannot tell if that works or not. [I encouraged them](https://chat.stackexchange.com/transcript/message/61990320#61990320) to post and answer here, but they didn't. – Martin R Jul 19 '23 at 15:02

0 Answers0