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 Ralph Goers <ra...@dslextreme.com> on 2014/01/27 03:19:48 UTC

Re: Enums and Custom Levels - a few minor changes

I modified Level to be final and have a private constructor.  I added a static method named getOrCreateLevel.  Custom extensions should use that method to create the static reference.  This allows the new Level to be declared in multiple places without a problem as they will all get the same Level instance.

I also removed the ordinal and the synchronization associated with it.

Ralph

On Jan 26, 2014, at 2:40 PM, Nick Williams <ni...@nicholaswilliams.net> wrote:

> I would be OK with getting rid of the ordinal. It makes it less enum-like, but I agree that the ordinal really has little purpose now. The intLevel is more important.
> 
> Here may be the best approach I can think of for calculating the StandardLevel-equivalent on instantiation:
> 
>    public static Level OFF = new Level("OFF", 0, StandardLevel.OFF) {};
>    ...
>    public static Level ALL = new Level("ALL", Integer.MAX_VALUE, StandardLevel.ALL);
> 
>    ...
> 
>    private Level(String name, int intLevel, StandardLevel standardLevel) { // this is the only c-tor standard levels use
>        // same logic as current constructor
>        this.standardLevel = standardLevel;
>    }
> 
>    protected Level(String name, int intLevel) { // this is the only c-tor custom levels use
>        this(name, intLevel, Level.calculateStandardLevel(intLevel));
>    }
> 
>    public enum StandardLevel {
>        OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL
>    }
> 
> Thoughts?
> 
> N


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: Enums and Custom Levels - a few minor changes

Posted by Remko Popma <re...@gmail.com>.
Understood. I can't commit from work but I can fix this when I get home
tonight.

On Monday, January 27, 2014, Ralph Goers <ra...@dslextreme.com> wrote:

> You mentioned that before and I didn’t check since it has been that way
> from the beginning.  Yes it looks like a bug to me.
>
> Ralph
>
> On Jan 26, 2014, at 7:06 PM, Remko Popma <remko.popma@gmail.com<javascript:_e({}, 'cvml', 'remko.popma@gmail.com');>>
> wrote:
>
> The switch in o.a.l.Category.getEffectiveLevel() in log4j-1.2-api is
> missing the FATAL level (and perhaps OFF also).
> Is this intentional?
>
> On Monday, January 27, 2014, Ralph Goers <ralph.goers@dslextreme.com<javascript:_e({}, 'cvml', 'ralph.goers@dslextreme.com');>>
> wrote:
>
>> I modified Level to be final and have a private constructor.  I added a
>> static method named getOrCreateLevel.  Custom extensions should use that
>> method to create the static reference.  This allows the new Level to be
>> declared in multiple places without a problem as they will all get the same
>> Level instance.
>>
>> I also removed the ordinal and the synchronization associated with it.
>>
>> Ralph
>>
>> On Jan 26, 2014, at 2:40 PM, Nick Williams <ni...@nicholaswilliams.net>
>> wrote:
>>
>> > I would be OK with getting rid of the ordinal. It makes it less
>> enum-like, but I agree that the ordinal really has little purpose now. The
>> intLevel is more important.
>> >
>> > Here may be the best approach I can think of for calculating the
>> StandardLevel-equivalent on instantiation:
>> >
>> >    public static Level OFF = new Level("OFF", 0, StandardLevel.OFF) {};
>> >    ...
>> >    public static Level ALL = new Level("ALL", Integer.MAX_VALUE,
>> StandardLevel.ALL);
>> >
>> >    ...
>> >
>> >    private Level(String name, int intLevel, StandardLevel
>> standardLevel) { // this is the only c-tor standard levels use
>> >        // same logic as current constructor
>> >        this.standardLevel = standardLevel;
>> >    }
>> >
>> >    protected Level(String name, int intLevel) { // this is the only
>> c-tor custom levels use
>> >        this(name, intLevel, Level.calculateStandardLevel(intLevel));
>> >    }
>> >
>> >    public enum StandardLevel {
>> >        OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL
>> >    }
>> >
>> > Thoughts?
>> >
>> > N
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>>
>>
>

Re: Enums and Custom Levels - a few minor changes

Posted by Ralph Goers <ra...@dslextreme.com>.
You mentioned that before and I didn’t check since it has been that way from the beginning.  Yes it looks like a bug to me.  

Ralph

On Jan 26, 2014, at 7:06 PM, Remko Popma <re...@gmail.com> wrote:

> The switch in o.a.l.Category.getEffectiveLevel() in log4j-1.2-api is missing the FATAL level (and perhaps OFF also). 
> Is this intentional?
> 
> On Monday, January 27, 2014, Ralph Goers <ra...@dslextreme.com> wrote:
> I modified Level to be final and have a private constructor.  I added a static method named getOrCreateLevel.  Custom extensions should use that method to create the static reference.  This allows the new Level to be declared in multiple places without a problem as they will all get the same Level instance.
> 
> I also removed the ordinal and the synchronization associated with it.
> 
> Ralph
> 
> On Jan 26, 2014, at 2:40 PM, Nick Williams <ni...@nicholaswilliams.net> wrote:
> 
> > I would be OK with getting rid of the ordinal. It makes it less enum-like, but I agree that the ordinal really has little purpose now. The intLevel is more important.
> >
> > Here may be the best approach I can think of for calculating the StandardLevel-equivalent on instantiation:
> >
> >    public static Level OFF = new Level("OFF", 0, StandardLevel.OFF) {};
> >    ...
> >    public static Level ALL = new Level("ALL", Integer.MAX_VALUE, StandardLevel.ALL);
> >
> >    ...
> >
> >    private Level(String name, int intLevel, StandardLevel standardLevel) { // this is the only c-tor standard levels use
> >        // same logic as current constructor
> >        this.standardLevel = standardLevel;
> >    }
> >
> >    protected Level(String name, int intLevel) { // this is the only c-tor custom levels use
> >        this(name, intLevel, Level.calculateStandardLevel(intLevel));
> >    }
> >
> >    public enum StandardLevel {
> >        OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL
> >    }
> >
> > Thoughts?
> >
> > N
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 


Re: Enums and Custom Levels - a few minor changes

Posted by Remko Popma <re...@gmail.com>.
The switch in o.a.l.Category.getEffectiveLevel() in log4j-1.2-api is
missing the FATAL level (and perhaps OFF also).
Is this intentional?

On Monday, January 27, 2014, Ralph Goers <ra...@dslextreme.com> wrote:

> I modified Level to be final and have a private constructor.  I added a
> static method named getOrCreateLevel.  Custom extensions should use that
> method to create the static reference.  This allows the new Level to be
> declared in multiple places without a problem as they will all get the same
> Level instance.
>
> I also removed the ordinal and the synchronization associated with it.
>
> Ralph
>
> On Jan 26, 2014, at 2:40 PM, Nick Williams <nicholas@nicholaswilliams.net<javascript:;>>
> wrote:
>
> > I would be OK with getting rid of the ordinal. It makes it less
> enum-like, but I agree that the ordinal really has little purpose now. The
> intLevel is more important.
> >
> > Here may be the best approach I can think of for calculating the
> StandardLevel-equivalent on instantiation:
> >
> >    public static Level OFF = new Level("OFF", 0, StandardLevel.OFF) {};
> >    ...
> >    public static Level ALL = new Level("ALL", Integer.MAX_VALUE,
> StandardLevel.ALL);
> >
> >    ...
> >
> >    private Level(String name, int intLevel, StandardLevel standardLevel)
> { // this is the only c-tor standard levels use
> >        // same logic as current constructor
> >        this.standardLevel = standardLevel;
> >    }
> >
> >    protected Level(String name, int intLevel) { // this is the only
> c-tor custom levels use
> >        this(name, intLevel, Level.calculateStandardLevel(intLevel));
> >    }
> >
> >    public enum StandardLevel {
> >        OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL
> >    }
> >
> > Thoughts?
> >
> > N
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org<javascript:;>
> For additional commands, e-mail: log4j-dev-help@logging.apache.org<javascript:;>
>
>