-3

Is there a way to parse iOS's log to a String at run time when it occurred? I need to parse a certain error log from UIKit and assert it at once when it appeared for debugging.

What we want to do is to parse the console for this error: This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes. We've found and fixed the line that causes this error, but we need to prevent this for happening again. FYI, the culprit is a line that changes a constant of an Autolayout in a background thread. And unfortunately it is not recognized by the compiler as an error like when we do the same thing with UIButton or anything that is derived from UIView (which will give an error at compile time when we try putting it in a background thread).

  • 1
    Which error log you need to read from UIKit ? Probably there is another way. You can't manipulate console log in your app, instead the trigger that raises exception could be used to determine that condition. – NeverHopeless Jan 29 '19 at 05:23
  • It's actually this error when we are changing Autolayout constraint on non main thread: `This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes`. We just found out about this error today and we are trying to make sure that there is no other occurrences of this error elsewhere. Browsing up for any code that triggered it will be quite a chore in this massive project. – Bawenang Rukmoko Pardian Putra Jan 29 '19 at 08:21
  • Are you adding constraints from code ? If yes, this is similar thread: https://stackoverflow.com/questions/28302019/getting-a-this-application-is-modifying-the-autolayout-engine-from-a-background – NeverHopeless Jan 29 '19 at 09:16
  • Well, we've found the cause and fixed it. But we decided that we need to guard if there were / going to be any other errors of the same type either in the current code base or in the future. It's kind of necessary in a massive project with more than 30 people working on it. – Bawenang Rukmoko Pardian Putra Jan 30 '19 at 02:47
  • 1
    Your _app_ cannot see a warning that the runtime puts into the _console_. The console message is talking to _you_, not your app. A human being needs to notice the message and deal with it. – matt Jan 30 '19 at 04:00

1 Answers1

0

After much googling for the answer, I've finally found the answer. I found this article:

So here's what I did:

  1. Eavesdropping on stderr stream
  2. Duplicate it into another string
  3. Parse the string for "weird crashes"
  4. If found, it will crash immediately (instead of still running the app and waiting for the app to crash at indefinite time)
  5. Added a DEBUG guard so that this functionality doesn't get carried over to production