You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2012/10/22 16:11:31 UTC

[v2] New Logger.isEnabled(Level) should be like v1's Category.isEnabledFor(Priority)

Hi All:

I added a new API in Logger: isEnabled(Level), which should be like v1's
Category.isEnabledFor(Priority).

It is implemented like this:

    public boolean isEnabled(Level level) {
        return isEnabled(level, null, (Object) null, null);
    }

I do not understand why this tests passes:
org.apache.logging.log4j.LoggerTest.isOffEnabled()

    @Test
    public void isOffEnabled() {
        assertTrue("Incorrect level", logger.isEnabled(Level.OFF));
    }

Thoughts?

Gary

-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: [v2] New Logger.isEnabled(Level) should be like v1's Category.isEnabledFor(Priority)

Posted by Gary Gregory <ga...@gmail.com>.
Done.

Gary

On Mon, Oct 22, 2012 at 12:18 PM, Ralph Goers <ra...@dslextreme.com>wrote:

> I guess the best solution is to note it in the javadoc and then always
> return true.
>
> Ralph
>
> On Oct 22, 2012, at 9:12 AM, Gary Gregory wrote:
>
> So... throw an IllegalArgumentException? Seems harsh. If not an exception,
> then returning true is the only option.
>
> ?
>
> Gary
>
> On Mon, Oct 22, 2012 at 11:34 AM, Ralph Goers <ra...@dslextreme.com>wrote:
>
>> I would suggest that isEnabled() specifically disallow Level.OFF as that
>> makes no sense.  The test for a level is
>>
>> intLevel <= level.intLevel.
>>
>> It is impossible for a Logger to ever have a level that will make this
>> result false.
>>
>> Ralph
>>
>>
>>
>>
>> On Oct 22, 2012, at 7:11 AM, Gary Gregory wrote:
>>
>> Hi All:
>>
>> I added a new API in Logger: isEnabled(Level), which should be like v1's
>> Category.isEnabledFor(Priority).
>>
>> It is implemented like this:
>>
>>     public boolean isEnabled(Level level) {
>>         return isEnabled(level, null, (Object) null, null);
>>     }
>>
>> I do not understand why this tests passes:
>> org.apache.logging.log4j.LoggerTest.isOffEnabled()
>>
>>     @Test
>>     public void isOffEnabled() {
>>         assertTrue("Incorrect level", logger.isEnabled(Level.OFF));
>>     }
>>
>> Thoughts?
>>
>> Gary
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> JUnit in Action, 2nd Ed: <http://goog_1249600977/>http://bit.ly/ECvg0
>> Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> JUnit in Action, 2nd Ed: <http://goog_1249600977/>http://bit.ly/ECvg0
> Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: [v2] New Logger.isEnabled(Level) should be like v1's Category.isEnabledFor(Priority)

Posted by Ralph Goers <ra...@dslextreme.com>.
I guess the best solution is to note it in the javadoc and then always return true.

Ralph

On Oct 22, 2012, at 9:12 AM, Gary Gregory wrote:

> So... throw an IllegalArgumentException? Seems harsh. If not an exception, then returning true is the only option.
> 
> ?
> 
> Gary
> 
> On Mon, Oct 22, 2012 at 11:34 AM, Ralph Goers <ra...@dslextreme.com> wrote:
> I would suggest that isEnabled() specifically disallow Level.OFF as that makes no sense.  The test for a level is 
> 
> intLevel <= level.intLevel.
> 
> It is impossible for a Logger to ever have a level that will make this result false.
> 
> Ralph
> 
> 
> 
> 
> On Oct 22, 2012, at 7:11 AM, Gary Gregory wrote:
> 
>> Hi All:
>> 
>> I added a new API in Logger: isEnabled(Level), which should be like v1's Category.isEnabledFor(Priority).
>> 
>> It is implemented like this:
>> 
>>     public boolean isEnabled(Level level) {
>>         return isEnabled(level, null, (Object) null, null);
>>     }
>> 
>> I do not understand why this tests passes: org.apache.logging.log4j.LoggerTest.isOffEnabled()
>> 
>>     @Test
>>     public void isOffEnabled() {
>>         assertTrue("Incorrect level", logger.isEnabled(Level.OFF));
>>     }
>> 
>> Thoughts?
>> 
>> Gary
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> JUnit in Action, 2nd Ed: http://bit.ly/ECvg0
>> Spring Batch in Action: http://bit.ly/bqpbCK
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> JUnit in Action, 2nd Ed: http://bit.ly/ECvg0
> Spring Batch in Action: http://bit.ly/bqpbCK
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory


Re: [v2] New Logger.isEnabled(Level) should be like v1's Category.isEnabledFor(Priority)

Posted by Gary Gregory <ga...@gmail.com>.
So... throw an IllegalArgumentException? Seems harsh. If not an exception,
then returning true is the only option.

?

Gary

On Mon, Oct 22, 2012 at 11:34 AM, Ralph Goers <ra...@dslextreme.com>wrote:

> I would suggest that isEnabled() specifically disallow Level.OFF as that
> makes no sense.  The test for a level is
>
> intLevel <= level.intLevel.
>
> It is impossible for a Logger to ever have a level that will make this
> result false.
>
> Ralph
>
>
>
>
> On Oct 22, 2012, at 7:11 AM, Gary Gregory wrote:
>
> Hi All:
>
> I added a new API in Logger: isEnabled(Level), which should be like v1's
> Category.isEnabledFor(Priority).
>
> It is implemented like this:
>
>     public boolean isEnabled(Level level) {
>         return isEnabled(level, null, (Object) null, null);
>     }
>
> I do not understand why this tests passes:
> org.apache.logging.log4j.LoggerTest.isOffEnabled()
>
>     @Test
>     public void isOffEnabled() {
>         assertTrue("Incorrect level", logger.isEnabled(Level.OFF));
>     }
>
> Thoughts?
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> JUnit in Action, 2nd Ed: <http://goog_1249600977/>http://bit.ly/ECvg0
> Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: [v2] New Logger.isEnabled(Level) should be like v1's Category.isEnabledFor(Priority)

Posted by Ralph Goers <ra...@dslextreme.com>.
I would suggest that isEnabled() specifically disallow Level.OFF as that makes no sense.  The test for a level is 

intLevel <= level.intLevel.

It is impossible for a Logger to ever have a level that will make this result false.

Ralph



On Oct 22, 2012, at 7:11 AM, Gary Gregory wrote:

> Hi All:
> 
> I added a new API in Logger: isEnabled(Level), which should be like v1's Category.isEnabledFor(Priority).
> 
> It is implemented like this:
> 
>     public boolean isEnabled(Level level) {
>         return isEnabled(level, null, (Object) null, null);
>     }
> 
> I do not understand why this tests passes: org.apache.logging.log4j.LoggerTest.isOffEnabled()
> 
>     @Test
>     public void isOffEnabled() {
>         assertTrue("Incorrect level", logger.isEnabled(Level.OFF));
>     }
> 
> Thoughts?
> 
> Gary
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> JUnit in Action, 2nd Ed: http://bit.ly/ECvg0
> Spring Batch in Action: http://bit.ly/bqpbCK
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory