I am trying to make a console window in my OS X application, which is basically displaying the content of the application log file stored in ~/Library/Application Support/CocosBuilder/cocosbuilder.log
I redirected all NSLog statement from my application inside this file:
+ (void)redirectNSLogToDocumentFolder
{
NSString *logFilePath = [self logfilePath];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}
Then I watch for modifications in the folder:
- (void)subscribeFileSystemChanges
{
NSString* _pathToObserve = [ConsoleWindow logfileDir];
NSArray * pathArray = [NSArray arrayWithObject:_pathToObserve];
// if already subscribed then unsubscribe
if (stream)
{
FSEventStreamStop(stream);
FSEventStreamInvalidate(stream);
FSEventStreamRelease(stream);
}
FSEventStreamContext context;
context.info = (__bridge void *)self;
context.version = 0;
context.retain = NULL;
context.release = NULL;
context.copyDescription = NULL;
stream = FSEventStreamCreate(kCFAllocatorDefault,
(FSEventStreamCallback)refreshConsoleTextView,
&context,
(__bridge CFArrayRef)pathArray,
kFSEventStreamEventIdSinceNow,
1.0,
kFSEventStreamCreateFlagWatchRoot);
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
}
My callback method refreshConsoleTextView is called when I add something to my log file from terminal with:
echo "toto" >> cocosbuilder.log
But it's not called when my own application writes something to they log file (with my NSLog redirection). I did not use the flag kFSEventStreamCreateFlagIgnoreSelf
Do you have any idea ?