Kenton,
I have a message that contains fields that should never be logged. It would be great if there was a way that the Message.toString() did not automatically convert everything to a text representation. I'd love it if it were an opt-in for the TextFormat instead of trying never to use toString() on those messages.
Since AbstractMessage.toString() currently calls the static method for TextFormat, would it be too much bloat to have an SPI layer there to attach a custom formatter? Or maybe just not have a toString() at all where everyone must explicitly use TextFormat.
The extra conditional isn't a problem--it's the fact that somewhere in the code there may be a string cast where the field may be converted is bad or in new code from a developer that isn't aware that toString() will behave that way.
Message myMessage;
log.debug("message={}", myMessage); // TextFormat.printToString()
if(log.isDebugEnabled()) {
log.debug("message={}", MyTextFormat.printToString(myMessage));
}
Thanks,
-- TJ