I like writing toolkit rules to fix stuff up. I like tracking what was
done, and usually do:

Set local variable ERROR-LOG as:
Local Variable ERROR-LOG
Text of next line

This works, but does NOT scale well. As you get into thousands of lines
of error logging it really bogs down. Understandably. (With trace on
it kills performance, with trace off, it still slows it down).

I was considering writing each line to a file via ECMA and as I did
that, I noticed the AppendLog function in Lib-AJC, thinking it was what
I wanted to write to a file, then as I read further, I wondered if maybe
that really is the answer to what I want.

Am I reading this right? This allows you to append text to a variable,
more efficiently than my above approach?

* Append to a log string. This method has been introduced to handle
appending to large strings.
* It minimizes the need to work on huge strings in XSLT/XPath.
* @param {String} log existing large string where another string
"append" should be
* appended to. This string might be Base64 encoded.
* @param {String} append the string to be appended to "log". This
string should not be
* Base64-encoded.
* @param {String} delimiter if appending to a log file you can use
this parameter to specify
* the line break. This helps the shrinking mechanism not to
cut off
* in the middle of a line.
* @param {boolean} b64 Specifies if the "log" input parameter and
the result of the method should be
* Base64 decoded and encoded.
* <i>Note that in the original AJC, this argument was a String
that with a value of "true" or "false"</i>
* @param {Number} maxsize Specifies the maximum length of the
methods result in numbers of
* characters or bytes.
* @type String
* @return The appended log.

// Note(sv): Removed debug parameter that was in AJC

function appendLog(log, append, delimiter, b64, maxsize)
var appended = "";

// decode before append
if (b64)
appended = new JString(Base64Codec.decode(log)) + append;
} catch (e)
appended = append;
// append
appended = log + append;
// free input variables
log = null;
append = null;
// shrink
var size = appended.length;
var shrinked = "";
if (size > maxsize)
var shrinkby = appended.indexOf(delimiter, size - maxsize) +
if (shrinkby < size - maxsize) shrinkby = size - maxsize;
shrinked = appended.substring(shrinkby);
shrinked = appended;
// free appended
appended = null;
// encode and return appended
if (b64)
var encoded = new String(Base64Codec.encode(shrinked.getBytes()));
return encoded;
// return appended
return shrinked;