Is this a good thing to do; to log via a method like this?
public static void log(final Object... messages) {
logger.info(Joiner.on(',').useForNull("null").join(messages));
}
// Where in other parts of code we can call the logger method using commas instead of string concatenation. Please note Joiner is a guava class.
log(" Check ",obja.getXXX(),anotherObject.getMethod());
Expectation is clean code, convenience and performance.
You will probably want to join on
' '(blank) rather than comma but the design approach is a nice idea.Performance wise, it’s not ideal. You create an additional object array and a joiner plus the internal buffers of the joiner.
So you can just get 2 of 3 with this approach. If you really care about performance, use slf4j which already uses a similar approach.