[Hawkular-dev] Logging ...
Thomas Segismont
tsegismo at redhat.com
Thu Jan 29 08:38:02 EST 2015
Le 28/01/2015 13:47, Heiko W.Rupp a écrit :
>
>> Am 28.01.2015 um 12:57 schrieb Lucas Ponce <lponce at redhat.com>:
>> Also, this point can be discussed later, but is there any convention for debug, like this one:
>>
>> if (LOG.isDebugEnabled()) {
>> LOG.debug("Message received: [{}]", msg);
>> }
>>
>> I mean, I like to use DEBUG for verbosity, but to reduce performance penalty, we can discuss a common approach.
>
> Isn't that relatively common usage anyway?
> Seriously - if some code has dozens of ifDebugEnabled() calls, it may make
> a lot of sense to factor that out to the start of the method or even in to the constructor
> so that this goes if (isDebug) ... { log.debug() }
>
As far as I understand this logging framework, parameters of the message
should be defined as parameters of a method in the logging interface
annotated with @MessageLogger. The method should define the logging level.
If my assumption is correct, then in most cases the #isXXXEnabled calls
can be avoided, as their purpose is to guard calls to #toString and
String concatenation.
Pursuing with Lucas' example, it should look like this:
MessagingLogger.LOGGER.messageReceived(msg);
With MessagingLogger looking like:
@MessageLogger(projectCode = "HAWK")
interface MessagingLogger extends BasicLogger {
/**
* The default logger.
*/
MessagingLogger LOGGER = ...;
@LogMessage(level = Level.DEBUG)
@Message(id = 1, value = "Message received: %s")
void messageReceived(String msg);
}
> Or do you mean the usage of the ugly uppercase LOG variable :-)?
Ugly is certainly a matter of taste :p
More information about the hawkular-dev
mailing list