Best way to use a textarea for keeping a log

Best way to use a textarea for keeping a log

Hi all,
 
I need to keep a log in a test application, so I'm using a textarea for that, and I'm appending text using the
+= operator.
Follows the trace function which fills the textarea:

window.trace = function(s) {
    if ($('#enableLogCheckBox').attr("checked")) {
        var logArea = $('#logArea')[0];
        logArea.value +=  s + "\n";
        logArea.scrollTop = logArea.scrollHeight;
    }
}

This technique has a serious problem, the application severly slows down as the number of lines in the text area increases, to the point to render the application unusable.

Ideally I'd like to log that to disk, but I know this doesn't seem currently possible (maybe with storage/gears?).

Can you suggest a better technique for logging text in a JS application?
An idea would be to keep a limited size array of lines and remove the old lines as long as new lines are added, but maybe someone can suggest a better solution or an existing plugin/component I'm not aware of.

Thanks in advance, greetz!