- (void)stderrRedirect:(NSString *)text { NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text]; /* Actually write the libhb output to the text view (outputTextStorage) */ [outputTextStorage appendAttributedString:attributedString]; [attributedString release]; /* remove text from outputTextStorage as defined by TextStorageUpperSizeLimit and TextStorageLowerSizeLimit */ if ([outputTextStorage length] > TextStorageUpperSizeLimit) [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length] - TextStorageLowerSizeLimit)]; [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)]; /* Now lets record the libhb output to our activity log file */ NSString *newOutputString = [[NSString alloc] initWithString:text]; /*get the current log file and put it into an NSString */ /* HACK ALERT: must be a way to do it without reading the whole log into memory Performance note: could batch write to the log, but want to get each line as it comes out of libhb in case of a crash or freeze so we see exactly what the last thing was before crash*/ NSString *currentOutputLogString = [[NSString alloc]initWithContentsOfFile:outputLogFile encoding:NSUTF8StringEncoding error:NULL]; /* Append the new libhb output string to the existing log file string */ currentOutputLogString = [currentOutputLogString stringByAppendingString:newOutputString]; /* Save the new modified log file string back to disk */ [currentOutputLogString writeToFile:outputLogFile atomically:YES encoding:NSUTF8StringEncoding error:NULL]; /* Release the new libhb output string */ [newOutputString release]; }