0

It's easy to "disable" NSLog at compile time by replacing it with a macro, etc.

Can NSLog (or ASL in general) be disabled at runtime?

My goal is to silence some logs that I do not have control over.

  • You can http://stackoverflow.com/questions/300673/is-it-true-that-one-should-not-use-nslog-on-production-code/17206296#17206296 – Lefteris Oct 22 '15 at 17:34
  • @Lefteris that is done at build time, not at runtime. –  Oct 22 '15 at 19:08

1 Answers1

0

Look at the Lumberjack Framework. There you can set the logging level as required. To hide certain log statements when you release the app, just change the logging level from say DEBUG to INFO using #ifdef RELEASE and #ifdef DEBUG macros.

Update:

In case the log statements are coming from a different framework that you are linking, you can use something like Method Swizzling to swap the implementation of NSlog with your custom method.

user3334059
  • 437
  • 3
  • 5
  • Will that silence a `NSLog` call? I cannot just replace the log calls with `DDLog` or anything else, they are in a pre-compiled framework. –  Oct 22 '15 at 15:31
  • Please see updated answer.. lmk in case you need more details about method swizzling. – user3334059 Oct 22 '15 at 19:23
  • 1
    How do you swizzle `NSLog`? It's a foundation foundation rather than a objective c method. – Tony Nov 29 '15 at 22:53
  • I don't see any reason why we won't be able swizzle foundation methods (see http://stackoverflow.com/questions/4553017/customizing-nslog-function-on-iphone), but it is not recommended as your app might be rejected from the store. Since the OP wanted to disable logging that might be happening from another framework, this was the only way that came to mind. – user3334059 Nov 30 '15 at 02:58