Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to hide or replace NSLog() function for a compiled third party library that keeps spewing debug into my logs?

GoogleConversionPlugin insists on logging random bits of useless information and screwing up my automated testing reports.

like image 620
Kirby Todd Avatar asked Jan 28 '13 14:01

Kirby Todd


1 Answers

You can redirect all NSLog() output to nowhere (or to a file other than the console log) or make it call your own logging output function (not officially but it works), however this will act on all NSLog() calls, not only on calls from this Google Plugin, also on calls from within your code. If your app is single threaded, you may get a way with your own logging function checking a global BOOL whether logging is currently enabled or disabled; yet in a multi-threaded environment, you would have to control that per thread (and if you use GCD you are multi-threaded even if you don't deal with threads yourself), which is also possible, albeit a bit more extra code.

So the question is, is it a useable to solution for you to disable logging globally (or for the current thread), make your plugin call and then turn it back on again? Of course, disabling per thread will not work if the plugin is multi-threaded internally (it may switch threads without you noticing), but in that case the global switch would still work.

Controlling only the NSLog() calls of a static library is not possible unless you are willing to "patch" this library (and you are allowed to do so without having Google sue you, of course). It would be possible for a dynamic library, but as you develop for iOS, you cannot use dynamic libraries.

So let me know which of these possible solution suits your needs, if any, and I will see what I can do for you (e.g. update the answer and add some code or instructions).

like image 177
Mecki Avatar answered Oct 06 '22 20:10

Mecki