iOS app logging somewhere other than Xcode console

There's an app I've started working on, that regularly logs to the console a lot of stuff, and it's really not convenient to use the console for additional debug logs. I don't want to erase these logs, because there are a few people that are maintaining these logs, and it might be important to them.

So I actually need to to write my debug stuff to a different place. one option is to write it to a file and watch it in Terminal using tail command, but an iOS app can only write inside its folder which, when using a simulator, is always changing each time I run the app. and I don't want to change the path int the tail command every time - I want a fast process.

Does anyone have an idea for such external log place that I can use easily?


1 Answers iOS app logging somewhere other than Xcode console

Here's how to make it easier to find and tail your log file when running in Simulator (I use this myself):

1) Add the following code to your home directory's .bashrc then log out and back in again.

    find . -name xcode.log -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" "

2) Start your app in Xcode's simulator, such that at least something gets logged to your file. Oh, and the file your app is logging to needs to be named "xcode.log" unless you want to change the filename in the above code.

3) Open terminal and switch to your ~/Library/Developer/CoreSimulator directory. Then perform the following command (it displays the last 100 lines of it along with anything new you dump to it).

tail -n 100 -f $(xcodelog)

So the above command hunts for that file among all your simulator devices and their apps, hunting down the most recent "xcode.log" file you've written to (among all apps and devices in entire CoreSimulator subdirectory system).

To clear the most recent xcode.log file, you can do this command:

cat /dev/null > $(xcodelog)

I switched to this approach for all my logging when Xcode 8 lost support for plugins, along with the very fine XcodeColors plugin that would do ANSI color logging into Xcode's console. So I changed my log system to output colors that terminal would support when doing a tail of a file. So I can spot errors in red, warnings in orange, user step logging in yellow, and various degrees of important other info in progressive shades of gray. :)

12 months ago