We left out later parts if we exceeded the maximum log size, which
was deeply unhelpful since the problem almost certainly happened
just before the user hit the 'submit debug logs' button.
Instead, iterate backwards through the fragments and prepend them,
leaving off the earlier ones if we run over the size.
Also, check we're not going to run over the size before adding
the fragment so we might actually stick to the maximum log size.
May fix https://github.com/vector-im/riot-web/issues/10951
Run the replace on the log line string instead of the separate
parts since we can ensure the line is a string.
Signed-off-by: Jason Robinson <jasonr@matrix.org>
If an individual log is larger than the max size, ignore the rest
of it. Also build the string as we go rather than joining it all
together at the end, that way we only need the whole string + one
chunk in memory at once, rather than the whole string x 2.