On Thu, Jun 9, 2016 at 4:28 PM, Abimaran Kugathasan <[email protected]>
wrote:

> I think, it's depends on the framework and their versions.
>
> latest versions of slf4j or log4j 2 don't require guard statements.
>
Have they mentioned about this somewhere?

> They use a parameterized log statement so that an event can be logged
> unconditionally, but message formatting only occurs if the event is
> enabled. Message construction is performed as needed by the logger, rather
> than pre-emptively by the application.
>
That's right, but if we have a guard condition, there won't be a string
object created in the runtime. This is what I said earlier and we need to
avoid unnecessary strings.

>
> On Thu, Jun 9, 2016 at 3:13 PM, Isuru Perera <[email protected]> wrote:
>
>> I think it's better to use isDebugEnabled for any debug log, even if it
>> is using parameters for a formatted string. If the debug is not enabled, we
>> don't even want to create the String object.
>>
>> No need to assign to a final variable. Checking the condition just before
>> logging should be enough.
>>
>> On Thu, Jun 9, 2016 at 3:06 PM, Afkham Azeez <[email protected]> wrote:
>>
>>> No need to do isDebugEnabled ideally for formatted logs.
>>>
>>> On Thu, Jun 9, 2016 at 3:01 PM, Jayanga Kaushalya <[email protected]>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> Do we need to check whether the isDebugEnabled() for formatted debug
>>>> logs without any string concatenations? For example below code:
>>>>
>>>> if (log.isDebugEnabled) {
>>>>    log.debug("Test log with var: {} and var: {}", var1, var2);
>>>> }
>>>>
>>>> If we have to check it is, what is the best way to check it? Assign it
>>>> to a final variable in the class header or check it every time where their
>>>> is a debug log like above code?
>>>>
>>>> Thanks!
>>>>
>>>> *Jayanga Kaushalya*
>>>> Software Engineer
>>>> Mobile: +94777860160
>>>> WSO2 Inc. | http://wso2.com
>>>> lean.enterprise.middleware
>>>>
>>>
>>>
>>>
>>> --
>>> *Afkham Azeez*
>>> Director of Architecture; WSO2, Inc.; http://wso2.com
>>> Member; Apache Software Foundation; http://www.apache.org/
>>> * <http://www.apache.org/>*
>>> *email: **[email protected]* <[email protected]>
>>> * cell: +94 77 3320919 <%2B94%2077%203320919>blog: *
>>> *http://blog.afkham.org* <http://blog.afkham.org>
>>> *twitter: **http://twitter.com/afkham_azeez*
>>> <http://twitter.com/afkham_azeez>
>>> *linked-in: **http://lk.linkedin.com/in/afkhamazeez
>>> <http://lk.linkedin.com/in/afkhamazeez>*
>>>
>>> *Lean . Enterprise . Middleware*
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Isuru Perera
>> Associate Technical Lead | WSO2, Inc. | http://wso2.com/
>> Lean . Enterprise . Middleware
>>
>> about.me/chrishantha
>> Contact: +IsuruPereraWSO2 <https://www.google.com/+IsuruPereraWSO2/about>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Thanks
> Abimaran Kugathasan
> Senior Software Engineer
>
> Email : [email protected]
> Mobile : +94 773922820
>
> <http://stackoverflow.com/users/515034>
> <http://lk.linkedin.com/in/abimaran>
> <http://www.lkabimaran.blogspot.com/>  <https://github.com/abimarank>
> <https://twitter.com/abimaran>
>
>


-- 
Isuru Perera
Associate Technical Lead | WSO2, Inc. | http://wso2.com/
Lean . Enterprise . Middleware

about.me/chrishantha
Contact: +IsuruPereraWSO2 <https://www.google.com/+IsuruPereraWSO2/about>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to