What you are trying to do can probably best be accomplished with the built in logging system. These can easily log (print out) the message you give it (along with the source file name, func/method, line number in the source code, etc.). Take a look through the built in logging facilities here, they are VERY helpful:
https://developer.apple.com/documentation/os/logging
https://developer.apple.com/videos/play/wwdc2023/10226/
Topic:
Programming Languages
SubTopic:
Swift
Tags: