keith-turner commented on issue #2495: URL: https://github.com/apache/accumulo/issues/2495#issuecomment-1039751024
> The problem with using something other than toString(), is that we have to remember to explicitly convert it ourselves, and we frequently forget to do that. A log builder or some other wrapper around logging could force us to do it, though (because its API could require some kind of Loggable object instead of accepting strings). Looked around for ways to have custom formatting for objects in log4j and found this : https://logging.apache.org/log4j/log4j-2.17.0/log4j-api/apidocs/org/apache/logging/log4j/util/StringBuilderFormattable.html ran the following test ```java package org.apache.accumulo.test; import org.apache.logging.log4j.util.StringBuilderFormattable; import org.slf4j.LoggerFactory; public class Test { public static class Foo implements StringBuilderFormattable { @Override public void formatTo(StringBuilder buffer) { buffer.append("TABLE_ID[99]"); } } @org.junit.Test public void test1(){ var log = LoggerFactory.getLogger("TL1"); log.info("This is only a test: {}", new Foo()); } } ``` which printed ``` 2022-02-14T20:20:35,625 [TL1] INFO : This is only a test: TABLE_ID[99] ``` So maybe the abstract id type could implement this interface for logging the id. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
