I have integrated a 3rd party framework into my app.
Periodically, this framework writes messages to the log.
Is there any way I can catch those messages in my application code?
I need to extract some useful data from there.
I have integrated a 3rd party framework into my app.
Periodically, this framework writes messages to the log.
Is there any way I can catch those messages in my application code?
I need to extract some useful data from there.
You say it writes it to a "log" - if it's a file it logs too, then write you own background task that looks at the file size every so often, and if it's changed then post a wakeup to some other part of your code. If its logging to "standard out" or "standard error" (fd==1 or fd==2), you can open your own log file and then reassign the FILE *. Now everything sent to stdout or stderr will get sent to your file.
EDIT: there are numerous posts on SO how to use freemen - its like one line of code - start with this one Rerouting stdin and stdout from C. You may have to experiment with the mode, but I suspect "a" will work, if not try "w". The file will be created if it does not exist.
The code will be something like `freopen(pathToMyLogFile, "a", stdout)', check the return code too. Search for the command in the Xcode document view or use man from the terminal.
If you know the logging method of the framework, I mean the method which contains NSLog of your interest, you can swizzle the method with your own and capture the messages before printing it.
In objC method name is mapped to its implementation(IMP). Exchanging method implementation(IMP) is called method swizzling. With method swizzling you can make method A to call IMP B and vice versa. There are many resources available to explain you in detail.
Applicability of this technique depends on the way the framework log information. However this can give you a lead to achieve what you are trying for.