If you want a simple log of output that you can position in one spot and not have Xcode mess with, this is what I ended up doing…
Override NSLog to output a file to my user root directory. Create an AppleScript that launched Terminal and made sure Terminal opened a window and tailed the output file with sed.
The benefit is that I've got a skinny output log that I can place anywhere on my screen(s) and I don't have to worry about Xcode's behaviours changing where I put my stuff. Also, the Xcode console is pretty poor when outputting long NSStrings and the dwell over a variable behaviour truncates long strings. This approach just displays what you output.
The downside is that it writes to my user folder, which is useless if you share your project with other people.
-- AppleScript below tell application "Terminal" activate set myDocument to window 1 -- nuke all chars up to ] off of the start of every new line set myShellString to "tail -f 'iPhone Simulator log.txt' | sed -e 's/.*]/]/g'" & return
do script myShellString in myDocument end tell end tell
-- Objective C below File: NSLogOverride.h // // NSLogOverride.h //
@interface OverrideNSLog : NSObject
+ (void)redirectNSLogToDocumentFolder;
@end
File: NSLogOverride.m // // NSLogOverride.m //
#import "OverrideNSLog.h"
@implementation OverrideNSLog + (void)redirectNSLogToDocumentFolder{ NSString *documentsDirectory = @"/Users/zav"; // Replace this with the path to your user root NSString *fileName =[NSString stringWithFormat:@"iPhone Simulator log.txt"]; NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName]; freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr); } @end
In my AppDelegate.m, or wherever I wanted to start redirecting the NSLogs I just called this:
// Override point for customization after application launch. [OverrideNSLog redirectNSLogToDocumentFolder];
|