LoggableComponent ?
Brent Putman
putmanb at georgetown.edu
Wed Jun 19 16:38:19 EDT 2013
On 6/19/13 4:24 PM, Tom Zeller wrote:
>
> What about just overriding toString() in lieu of getLogPrefix() ?
toString() of what, the class calling the logging? Perhaps. But I
don't think we were necessarily saying that standardizing (in a
particular class hierarchy) on a getLogPrefix() method was bad. It's
probably good. It just doesn't seem to make much sense to be a public
Interface method, as opposed to just being a protected method and
implementation detail of the class. IMHO.
I think the simple approach of a a getLogPrefix() method convention
combined with a utility method that prepends the prefix to the supplied
message string probably eliminates a lot of the concerns (that I have at
least) about all the tedious, hardcoded boilerplate.
E.g.
log.info(LogSupport.withPrefix(getLogPrefix(), "My logged message"));
where withPrefix(...) is something like:
return String.format("%s: %s", prefix, message);
The point being that if we ever want to change any of that, we just do
it in one place.
And/or the log support method(s) could take the caller's reference, and
be intelligent and pull things like the component Id or whatever it
wanted, based on interfaces and reflection. If we wanted to do
something like this pattern, then the LoggableComponent interface would
make more sense.
More information about the dev
mailing list