Can anyone help with an issue I'm having redirecting console output to a logfile? I've been able to find a lot of info on the web about this and have used various different approaches, but I still haven't managed to figure out a complete solution. I've based my approach on one I found here.
I created a very simple demo app to show the issue. Here's the code for the view controller.
I deliberately used a bad URL in order to produce an error.
Here's the relevant code in the FileLogger class.
When I run this code in the debugger, I see the following in the Xcode console:
The output contains messages generated both from my print statements as well as system output telling me about the network error. When I look at the log file, it also contains all the output I see in the console. So far, so good.
The problem is when I run the same code when the debugger is not attached (in other words, in the actual use case for this functionality). In that case, the log file contains only the outut from my print statements, but not the system output.
Can anybody tell me what I'm doing wrong? Does the system output go into some stream other than STDOUT or STDERR when the debugger is not attached? Or is it suppressed entirely when the debugger isn't attached?
Any help with this would be very much appreciated.
SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.