IOS10 print all the Xcode console log into an UITextview inside an iPhone App page

I was trying to print my Xcode console log into an UITextView inside one of my app pages.

And I want the log info can be updated in real time just like debugging the app when I connect my iPhone to the Xcode console.

(I do this because I want some testers in my company can test the APP without connecting the iPhone to the Mac.In this way they can view the log info inside the app.)

Is there a way to do it?

I have checked few solutions like: redirect NSlog to file which is an old fashion way.

Now in iOS10, apple is using Unified Logging and Activity Tracing I watched the new video

https://developer.apple.com/videos/play/wwdc2016/721/

and I also checked the links below.

https://developer.apple.com/reference/os/logging?language=objc


https://developer.apple.com/library/content/samplecode/Logging/Introduction/Intro.html#//apple_ref/doc/uid/TP40017510-Intro-DontLinkElementID_2


but I still have no idea how am I gonna do this?


Apple docs seems said that the log messages can only be viewed via

Xcode's console, Console application, or via the `log` tool.



But how can I print all my console logs into one of my APP pages and make sure the log info is being update in real time?


Anyone can show me some sample objective-c code or swift code how to do this exactly?

Thanks so much!

Replies

If you’re trying to catch log output from code you control, my recommendation is that you implement your own logging function that can redirect the log messages to wherever you want.

OTOH, if you’re trying to catch log messages generated by code you don’t control, that’s not going to work on current system. To quote from the WWDC session you referenced:

First off, all of the ASL logging APIs are now superseded by these new APIs and, therefore, those old APIs are deprecated.

There is an interesting edge case though. A new API for searching the log data is not going to be made public in this release.

What that means is that there’s no equivalent to asl search functionality.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

It's extremely frustrating that Apple has gone through so much trouble creating a logging system that is space and time efficient and reliable but provides no reasonable way for users to mail an archive from iOS to the developer. The overhead of sysdiagnose is way too much for our testers, and we can't require them to connect their phone to a computer to deliver a log. For testing we generate high volumes of log data and we want our testers to easily send the data to us. It's too much data to spool to a log server without bogging down the iPhone. We use cocoaLumberjack right now because it's the only thing we can find that will do log rotation for us, and produce files we can email, but it's slow, it deadlocks, it doesn't flush reliably and loses data, and the log rotation algorithms are buggy and we end up with multi-gigabyte log files despite restricting the file size to 10 MB. If we could at least run the Unified Logging log command-line tool within our app through an API on ios (restricted to our own log data), then we could extract what we needed.

I second Papley's request. If my app crashes I want to attach the log file to the automatically generated crash report (I use Instabug.) Right now I am using SwiftyBeaver to a file destination that I have to manually rotate/delete as necessary if the log gets too big.