Finally I found the way, when I append text to the NSTextStorage, I just control if the length surpasses a threshold value and I clean some space of the log beginning:
// updates the textarea for incoming text by appending text
- (void)appendToIncomingText: (id) text {
// add the text to the textarea
NSAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: text];
NSTextStorage *textStorage = [SerialOutput textStorage];
[textStorage beginEditing];
[textStorage appendAttributedString:attrString];
//Max. size of TextArea: LOG_SIZE characters
if ([textStorage length] > LOG_SIZE){
[textStorage deleteCharactersInRange:NSMakeRange(0, [attrString length])];
}
[textStorage endEditing];
// scroll to the bottom
NSRange myRange;
myRange.length = 1;
myRange.location = [textStorage length];
NS[SerialOutput scrollRangeToVisible:myRange];
}
It works as a circular log, as I wanted.