Improve GC debug log message code

This fixes PR 13998 and also simplifies some code to reduce the chance of getting buffer overruns. The one downside is that the output is no longer formatted with commas.