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 2016/02/08 19:12:36 UTC

Locating the caller in LogEvent

I just now noticed that Log4jLogEvent’s calcLocation method is using a Throwable to locate the caller. For some reason I thought this was using ReflectionUtil.getCallerClass(fqcn).  I don’t know how this slipped through as I believe it should improve logging with location information quite a bit.  

Can anyone think of a reason not to do this?

Ralph

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


Re: Locating the caller in LogEvent

Posted by Matt Sicker <bo...@gmail.com>.
http://cr.openjdk.java.net/~mchung/jdk9/jep259/api/java/lang/StackWalker.StackFrame.html

Looks like StackWalker will provide what we need. Though we'll have to
update our API to use some abstraction over StackTraceElement and
StackFrame.

On 8 February 2016 at 14:47, Ralph Goers <ra...@dslextreme.com> wrote:

> No, you didn’t miss it. Now that I look at it ReflectionUtil is only
> getting the Class of the caller. We actually need the stack trace entry.
> Here is where the Java 9 stack walker API will help (I hope).
>
> Ralph
>
> On Feb 8, 2016, at 11:51 AM, Matt Sicker <bo...@gmail.com> wrote:
>
> I did a bit of refactoring when I put everything together in
> ReflectionUtil. I probably just missed that. I don't see any reason not to
> use it.
>
> On 8 February 2016 at 12:12, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
>> I just now noticed that Log4jLogEvent’s calcLocation method is using a
>> Throwable to locate the caller. For some reason I thought this was using
>> ReflectionUtil.getCallerClass(fqcn).  I don’t know how this slipped through
>> as I believe it should improve logging with location information quite a
>> bit.
>>
>> Can anyone think of a reason not to do this?
>>
>> Ralph
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: Locating the caller in LogEvent

Posted by Ralph Goers <ra...@dslextreme.com>.
No, you didn’t miss it. Now that I look at it ReflectionUtil is only getting the Class of the caller. We actually need the stack trace entry.  Here is where the Java 9 stack walker API will help (I hope).

Ralph

> On Feb 8, 2016, at 11:51 AM, Matt Sicker <bo...@gmail.com> wrote:
> 
> I did a bit of refactoring when I put everything together in ReflectionUtil. I probably just missed that. I don't see any reason not to use it.
> 
> On 8 February 2016 at 12:12, Ralph Goers <ralph.goers@dslextreme.com <ma...@dslextreme.com>> wrote:
> I just now noticed that Log4jLogEvent’s calcLocation method is using a Throwable to locate the caller. For some reason I thought this was using ReflectionUtil.getCallerClass(fqcn).  I don’t know how this slipped through as I believe it should improve logging with location information quite a bit.
> 
> Can anyone think of a reason not to do this?
> 
> Ralph
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org <ma...@logging.apache.org>
> For additional commands, e-mail: log4j-dev-help@logging.apache.org <ma...@logging.apache.org>
> 
> 
> 
> 
> -- 
> Matt Sicker <boards@gmail.com <ma...@gmail.com>>


Re: Locating the caller in LogEvent

Posted by Matt Sicker <bo...@gmail.com>.
I did a bit of refactoring when I put everything together in
ReflectionUtil. I probably just missed that. I don't see any reason not to
use it.

On 8 February 2016 at 12:12, Ralph Goers <ra...@dslextreme.com> wrote:

> I just now noticed that Log4jLogEvent’s calcLocation method is using a
> Throwable to locate the caller. For some reason I thought this was using
> ReflectionUtil.getCallerClass(fqcn).  I don’t know how this slipped through
> as I believe it should improve logging with location information quite a
> bit.
>
> Can anyone think of a reason not to do this?
>
> Ralph
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>


-- 
Matt Sicker <bo...@gmail.com>