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 Jim Moore <ji...@veritas.com> on 2001/06/15 02:31:41 UTC

thread name in LoggingEvent

As was just brought out on the Users list, the thread name is part of the
LoggingEvent, but the current implementation is:
  public String getThreadName() {
    if(threadName == null)
      threadName = (Thread.currentThread()).getName();
    return threadName;
  }
so if it's not asked for that information until it's in an AsyncAppender (or
having been serialized to a server) then it will give the wrong name.

Any reason for threadName to not get set at LoggingEvent creation?

-Jim Moore

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


Re: thread name in LoggingEvent

Posted by Anders Kristensen <ak...@dynamicsoft.com>.
I don't really care much but it could still be left as a config option.

Anders

Ceki Gülcü wrote:
> 
> There can be many appenders attached to an AsyncAppender and their layouts may change dynamically. Trying to optimize this is imho pushing it too far. :-) Cheers, Ceki
> 
> At 12:21 15.06.2001 -0400, you wrote:
> >Might be worthwhile making it optional whether to fill in thread name
> >with AsyncAppender as it's not always needed. Or else, I suppose, it
> >could be clever and figure it out itself from the configured layout.
> >
> >Anders
> >
> >
> >Ceki Gülcü wrote:
> >>
> >> Jim,
> >>
> >> That's true but in AsyncAppender:
> >>
> >> public
> >> void append(LoggingEvent event) {
> >>   // Set the NDC and thread name for the calling thread as these
> >>   // LoggingEvent fields were not set at event creation time.
> >>   event.getNDC();
> >>   event.getThreadName();
> >>   if(locationInfo) {
> >>     event.getLocationInformation();
> >>   }
> >>   ...
> >>  }
> >>
> >> Fetching the current thread takes a few milliseconds compared to a mehtod call which takes a few dozen nanoseconds. The idea is to avoid the cost of Thread.currentThread if it is not required. Hence the lazy fill in of the thread name field. In AsyncAppender we can no longer rely on being in the same thread so it gets filled in at the start of AsyncAppender.doAppend. Hope this clarifies the issue. Ceki
> >>
> >> At 19:31 14.06.2001 -0500, Jim Moore wrote:
> >> >As was just brought out on the Users list, the thread name is part of the
> >> >LoggingEvent, but the current implementation is:
> >> >  public String getThreadName() {
> >> >    if(threadName == null)
> >> >      threadName = (Thread.currentThread()).getName();
> >> >    return threadName;
> >> >  }
> >> >so if it's not asked for that information until it's in an AsyncAppender (or
> >> >having been serialized to a server) then it will give the wrong name.
> >> >
> >> >Any reason for threadName to not get set at LoggingEvent creation?
> >> >
> >> >-Jim Moore
> >> >
> >> >---------------------------------------------------------------------
> >> >To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
> >> >For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
> >>
> >> --
> >> Ceki Gülcü
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
> 
> --
> Ceki Gülcü
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

--
Anders Kristensen

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


Re: thread name in LoggingEvent

Posted by Ceki Gülcü <cg...@qos.ch>.
There can be many appenders attached to an AsyncAppender and their layouts may change dynamically. Trying to optimize this is imho pushing it too far. :-) Cheers, Ceki 

At 12:21 15.06.2001 -0400, you wrote:
>Might be worthwhile making it optional whether to fill in thread name
>with AsyncAppender as it's not always needed. Or else, I suppose, it
>could be clever and figure it out itself from the configured layout.
>
>Anders
>
>
>Ceki Gülcü wrote:
>> 
>> Jim,
>> 
>> That's true but in AsyncAppender:
>> 
>> public
>> void append(LoggingEvent event) {
>>   // Set the NDC and thread name for the calling thread as these
>>   // LoggingEvent fields were not set at event creation time.
>>   event.getNDC();
>>   event.getThreadName();
>>   if(locationInfo) {
>>     event.getLocationInformation();
>>   }
>>   ...
>>  }
>> 
>> Fetching the current thread takes a few milliseconds compared to a mehtod call which takes a few dozen nanoseconds. The idea is to avoid the cost of Thread.currentThread if it is not required. Hence the lazy fill in of the thread name field. In AsyncAppender we can no longer rely on being in the same thread so it gets filled in at the start of AsyncAppender.doAppend. Hope this clarifies the issue. Ceki
>> 
>> At 19:31 14.06.2001 -0500, Jim Moore wrote:
>> >As was just brought out on the Users list, the thread name is part of the
>> >LoggingEvent, but the current implementation is:
>> >  public String getThreadName() {
>> >    if(threadName == null)
>> >      threadName = (Thread.currentThread()).getName();
>> >    return threadName;
>> >  }
>> >so if it's not asked for that information until it's in an AsyncAppender (or
>> >having been serialized to a server) then it will give the wrong name.
>> >
>> >Any reason for threadName to not get set at LoggingEvent creation?
>> >
>> >-Jim Moore
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>> >For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>> 
>> --
>> Ceki Gülcü
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

--
Ceki Gülcü


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


Re: thread name in LoggingEvent

Posted by Anders Kristensen <ak...@dynamicsoft.com>.
Might be worthwhile making it optional whether to fill in thread name
with AsyncAppender as it's not always needed. Or else, I suppose, it
could be clever and figure it out itself from the configured layout.

Anders


Ceki Gülcü wrote:
> 
> Jim,
> 
> That's true but in AsyncAppender:
> 
> public
> void append(LoggingEvent event) {
>   // Set the NDC and thread name for the calling thread as these
>   // LoggingEvent fields were not set at event creation time.
>   event.getNDC();
>   event.getThreadName();
>   if(locationInfo) {
>     event.getLocationInformation();
>   }
>   ...
>  }
> 
> Fetching the current thread takes a few milliseconds compared to a mehtod call which takes a few dozen nanoseconds. The idea is to avoid the cost of Thread.currentThread if it is not required. Hence the lazy fill in of the thread name field. In AsyncAppender we can no longer rely on being in the same thread so it gets filled in at the start of AsyncAppender.doAppend. Hope this clarifies the issue. Ceki
> 
> At 19:31 14.06.2001 -0500, Jim Moore wrote:
> >As was just brought out on the Users list, the thread name is part of the
> >LoggingEvent, but the current implementation is:
> >  public String getThreadName() {
> >    if(threadName == null)
> >      threadName = (Thread.currentThread()).getName();
> >    return threadName;
> >  }
> >so if it's not asked for that information until it's in an AsyncAppender (or
> >having been serialized to a server) then it will give the wrong name.
> >
> >Any reason for threadName to not get set at LoggingEvent creation?
> >
> >-Jim Moore
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
> 
> --
> Ceki Gülcü
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

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


Re: thread name in LoggingEvent

Posted by Ceki Gülcü <cg...@qos.ch>.
Jim,

That's true but in AsyncAppender:

public
void append(LoggingEvent event) {
  // Set the NDC and thread name for the calling thread as these
  // LoggingEvent fields were not set at event creation time.
  event.getNDC();
  event.getThreadName();
  if(locationInfo) {
    event.getLocationInformation(); 
  }
  ...
 }

Fetching the current thread takes a few milliseconds compared to a mehtod call which takes a few dozen nanoseconds. The idea is to avoid the cost of Thread.currentThread if it is not required. Hence the lazy fill in of the thread name field. In AsyncAppender we can no longer rely on being in the same thread so it gets filled in at the start of AsyncAppender.doAppend. Hope this clarifies the issue. Ceki



At 19:31 14.06.2001 -0500, Jim Moore wrote:
>As was just brought out on the Users list, the thread name is part of the
>LoggingEvent, but the current implementation is:
>  public String getThreadName() {
>    if(threadName == null)
>      threadName = (Thread.currentThread()).getName();
>    return threadName;
>  }
>so if it's not asked for that information until it's in an AsyncAppender (or
>having been serialized to a server) then it will give the wrong name.
>
>Any reason for threadName to not get set at LoggingEvent creation?
>
>-Jim Moore
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

--
Ceki Gülcü


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