I'm working on a company project that requires me to log to a specific server, but I want to log to the console simultaneously. I use a custom logging class that I can feed a log message, a log level, a category and the source location where the log message was generated. Depending on where the app runs, it will log to the console (development), a development backend (test) or the production backend (production).
With Xcode 15 I'm finding the console output of OSLog beautiful and want to use it instead of the print statement. Now I want to also utilize the functionality of OSLog as much as I can and one thing is bothering me: right clicking a log entry in the console and using "Jump to source" always shows the line inside the class where I determine if we log to OSLog or to one of the backends.
Reading through Apple's documentation and looking at the available methods I can't find a way to override the default source location used by OSLog/Xcode to determine the source of a log message. Is there a way to modify it?
You can't. Apple implemented OSLog on a compiler/toolchain level, so the option to pass in file and line info is unavailable.
This unfortunately means you'll have to use OSLog directly, not wrapped, in order to get the Xcode integration working.