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/09/26 22:52:35 UTC

org.apache.logging.log4j.core.Logger.toString()

Hi All:

I was doing some debugging in a 1.2 app and was annoyed that
Logger.toString() did nothing helpful.

Any objection to implementing
org.apache.logging.log4j.core.Logger.toString()?

How about {name}:{level}? For example, "com.foo.Bar:INFO" or
"com.foo.Bar@INFO"

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: org.apache.logging.log4j.core.Logger.toString()

Posted by Gary Gregory <ga...@gmail.com>.
Roger that.

The current impl is null-safe, which I believe is the way to go for most
toString()s to deal with (me) fiddling with values in a debugger:

   /**     * Returns a String representation of this instance in the
form {@code "name:level[ in context_name]"}.     */
    public String toString() {
        final String nameLevel = "" + name + ":" + getLevel();
        if (context == null) {
            return nameLevel;
        }
        final String contextName = context.getName();
        return contextName == null ? nameLevel : nameLevel + " in " +
contextName;
    }

Gary

On Fri, Sep 28, 2012 at 3:50 PM, Ralph Goers <ra...@dslextreme.com>wrote:

> Looks good - thanks!
>
> A LoggerContext is always created by a ContextSelector. The three
> implementations that exist always provide a name.  However, at the moment a
> user could create their own selector that doesn't.
>
> Ralph
>
>
> On Sep 28, 2012, at 12:21 PM, Gary Gregory wrote:
>
> OK, here is an example of what I committed:
>
> LoggerTest:TRACE in sun.misc.Launcher$AppClassLoader@1ea2dfe
>
> Can a Logger's context ever be null? getParent() does not guard for this
> but I am toString() check to avoid NPEs.
>
> Can a LogerContext's name ever be null? The LC constructor does not check.
>
> Gary
>
> On Wed, Sep 26, 2012 at 5:05 PM, Ralph Goers <ra...@dslextreme.com>wrote:
>
>> I think that is a good idea. I would add the LoggerContext name to the
>> string if one is there.
>>
>> Ralph
>>
>>
>>
>> On Sep 26, 2012, at 1:52 PM, Gary Gregory wrote:
>>
>> Hi All:
>>
>> I was doing some debugging in a 1.2 app and was annoyed that
>> Logger.toString() did nothing helpful.
>>
>> Any objection to implementing
>> org.apache.logging.log4j.core.Logger.toString()?
>>
>> How about {name}:{level}? For example, "com.foo.Bar:INFO" or
>> "com.foo.Bar@INFO"
>>
>> 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: org.apache.logging.log4j.core.Logger.toString()

Posted by Ralph Goers <ra...@dslextreme.com>.
Looks good - thanks!

A LoggerContext is always created by a ContextSelector. The three implementations that exist always provide a name.  However, at the moment a user could create their own selector that doesn't.

Ralph


On Sep 28, 2012, at 12:21 PM, Gary Gregory wrote:

> OK, here is an example of what I committed:
> 
> LoggerTest:TRACE in sun.misc.Launcher$AppClassLoader@1ea2dfe
> 
> Can a Logger's context ever be null? getParent() does not guard for this but I am toString() check to avoid NPEs.
> 
> Can a LogerContext's name ever be null? The LC constructor does not check.
> 
> Gary
> 
> On Wed, Sep 26, 2012 at 5:05 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> I think that is a good idea. I would add the LoggerContext name to the string if one is there.
> 
> Ralph
> 
> 
> 
> On Sep 26, 2012, at 1:52 PM, Gary Gregory wrote:
> 
>> Hi All:
>> 
>> I was doing some debugging in a 1.2 app and was annoyed that Logger.toString() did nothing helpful.
>> 
>> Any objection to implementing org.apache.logging.log4j.core.Logger.toString()?
>> 
>> How about {name}:{level}? For example, "com.foo.Bar:INFO" or "com.foo.Bar@INFO" 
>> 
>> 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: org.apache.logging.log4j.core.Logger.toString()

Posted by Gary Gregory <ga...@gmail.com>.
OK, here is an example of what I committed:

LoggerTest:TRACE in sun.misc.Launcher$AppClassLoader@1ea2dfe

Can a Logger's context ever be null? getParent() does not guard for this
but I am toString() check to avoid NPEs.

Can a LogerContext's name ever be null? The LC constructor does not check.

Gary

On Wed, Sep 26, 2012 at 5:05 PM, Ralph Goers <ra...@dslextreme.com>wrote:

> I think that is a good idea. I would add the LoggerContext name to the
> string if one is there.
>
> Ralph
>
>
>
> On Sep 26, 2012, at 1:52 PM, Gary Gregory wrote:
>
> Hi All:
>
> I was doing some debugging in a 1.2 app and was annoyed that
> Logger.toString() did nothing helpful.
>
> Any objection to implementing
> org.apache.logging.log4j.core.Logger.toString()?
>
> How about {name}:{level}? For example, "com.foo.Bar:INFO" or
> "com.foo.Bar@INFO"
>
> 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: org.apache.logging.log4j.core.Logger.toString()

Posted by Ralph Goers <ra...@dslextreme.com>.
I think that is a good idea. I would add the LoggerContext name to the string if one is there.

Ralph


On Sep 26, 2012, at 1:52 PM, Gary Gregory wrote:

> Hi All:
> 
> I was doing some debugging in a 1.2 app and was annoyed that Logger.toString() did nothing helpful.
> 
> Any objection to implementing org.apache.logging.log4j.core.Logger.toString()?
> 
> How about {name}:{level}? For example, "com.foo.Bar:INFO" or "com.foo.Bar@INFO" 
> 
> 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