As a quick note today, I used to get the text from a stack trace in Java or Scala and then log it like this:
// this works, but it's not too useful/readable
In that code,
getStackTrace returns a sequence, which I convert to a
String before printing it.
But recently I learned the following technique, which does a much better job of keeping the formatting when getting the text from a stack trace, and then writing it to a file with a logger: