2008 08 17Redirecting NSLog with NSLogConsole
NSLog
.
NSLogConsole
captures NSLog
data (from stderr
) and redirects it to a console. It still forwards it to XCode's and also appears in Console.app. I've redirected to an html console, but you can do pretty much anything with the data : save it to a file, mail it, discard it, filter it …
Sample code
Usage
- Copy NSLogConsole.(m h html xib) in your project
- Add
#define NSLog(args...) NSLog(args), NSLogPostLog(__FILE__, __LINE__)
to your project's precompiled header - Start it with
[NSLogConsole sharedConsole]
to capture messages, open it with[[NSLogConsole sharedConsole] open]
Thanks to …
- Aleksandr Skobelev redirecting stderr
- AgentM log file and line number
- Rick Altherr open in XCode script
MIT license. Use freely !
Right now, launching from the Finder blocks on reading … works fine in XCode and Terminal. So don't use in production code :) Somehow stderr doesn't behave the same from Finder and from XCode. Any ideas ?
Thanks for this wonderful peace of code. While testing I found that -init of NSLogConsole is called twice: 1st by NIB-Loader and 2nd by -sharedConsole.
Thx,first.
I run your code, in my prj. Some error comes up for webview didnot load html file before invoking it.
So I add some code below:In -[logData:file:lineNumber:]
if (![webView isWebViewLoaded]) {
return;}
In NSLogConsoleView - (BOOL)isWebViewLoaded;
wow, great tool...thx!!
is there some sort of restriction to the source? or is it public domain?
Karsten