Hi again, I have another question about best practices with flogger.
My team is working on a project which uses a lot of concurrency.
Currently a lot of our log statements look like this: logger.atInfo().log("[Thread:%s]..."), Thread.currentThread().getName(), ...);
As you can imagine, sometimes we forget to add the thread name to the log message, and having every message start with "[Thread%s]" does seem cumbersome.
A little better way would be (although this doesn't solve anything, just stylistically):
logger.atInfo().withThread(Thread.currentThread().getName()).log(...);
logger.atInfo().withThread(Thread.currentThread().getId()).log(...);
An even better way would be (still, just syntactic sugar):
logger.atInfo().withThreadName().log(...);
logger.atInfo().withThreadId().log(...);
And finally, maybe a logger implementation that always prints the thread name/id:
private static final ThreadAwareFluentLogger logger = ThreadAwareFluentLogger.forEnclosingClass(USE_THREAD_NAME); // or something similar
...
logger.atInfo().log("...");
My first question is, am I asking something stupid :)?
Before using flogger we were using JUL which did not offer native support for logging the thread name/id either.
But I believe log4j, or slf4j, or one of them does.
If I am not asking something stupid, then, what would be the best way to go about implementing this? And do you think this should be a feature of flogger?
If I understand correctly, my options are:
1) See if MetadataKey would work for this use case.
2) Create a customer logger, with a custom concrete api implementation, and a custom back-end.
Thoughts?
Thanks a lot.