views:

331

answers:

3

Is there a way to force suppression of all logging in a Mac OS X desktop Cocoa app?

Sometimes some part of the system or a plugin (which is out of your control) will log messages on behalf of your application to the console (system.log).

Is there a way to suppress all logging in your application?

+4  A: 

You could use freopen to change where stdout and sterr point to:

http://www.opengroup.org/onlinepubs/000095399/functions/freopen.html

Gabe
I don't think that will affect ASL (which is what NSLog uses).
Peter Hosey
+4  A: 

@gabe: was just going to suggest something similar - just tried it out, and a simple 'fclose(stderr)' seems to prevent any output.

atebits
that does indeed do the trick. thx loren.
Todd Ditchendorf
A: 

I've also done this whenever I've needed to redirect console output to a custom view:

stderr->_write = RedirectOutputToView;
stdout->_write = RedirectOutputToView;

Where RedirectOutputToView has the following prototype:

int RedirectOutputToView(void *inFD, const char *buffer, int size);
Azeem.Butt